page.tld 已经在WEB-INF目录下面了吗?

解决方案 »

  1.   

    给你一个最简单的例子,来自《Professional JSP Tag Libraries》,仅供参考
    // DateTag.java
    package com.liad.jsptaglibs.date;import java.text.DateFormat;
    import java.util.Date;
    import java.util.Locale;import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.JspTagException;
    import javax.servlet.jsp.tagext.TagSupport;/**
     * A custom tag that displays the current date.
     *
     * @author    Simon Brown
     */
    public class DateTag extends TagSupport {  /**
       * Called when the starting tag is encountered.
       */
      public int doStartTag() throws JspException {    // get the locale of the client and create an appropriate date format
        Locale loc = pageContext.getRequest().getLocale();
        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, loc);    try {
          // and write out the formatted date to the page
          pageContext.getOut().write(df.format(new Date()));
        } catch (java.io.IOException ioe) {
          throw new JspTagException(ioe.getMessage());
        }    // and skip evaluating the body of the tag (as there shouldn't be one)
        return SKIP_PAGE;
      }}simple.tld
    ==========
    <?xml version="1.0" encoding="ISO-8859-1" ?> 
    <!DOCTYPE taglib
      PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
      "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"><taglib>   <tlib-version>1.0</tlib-version> 
      <jsp-version>1.2</jsp-version>
      <short-name>simple</short-name>
      <description>Examples for the Simple Tags chapter</description>
      
      <tag> 
        <name>date</name> 
        <tag-class>com.liad.jsptaglibs.date.DateTag</tag-class>
        <body-content>empty</body-content>
        <description>Inserts the current date into the page</description> 
      </tag>
      
    </taglib>web.xml
    =======
    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'><web-app>
      <display-name>Professional JSP Tag Libraries</display-name>
      <taglib>
        <taglib-uri>/simpleTaglib</taglib-uri>
        <taglib-location>/WEB-INF/tlds/simple.tld</taglib-location>
      </taglib>
    </web-app>datetag.jsp
    ===========
    <html>  <head>
        <title>Professional JSP Tag Libraries</title>
      </head>  <%@ taglib uri="/simpleTaglib" prefix="simple" %>  <body>    <h1>The date is <simple:date/></h1>  </body></html>用dos命令tree /f获得的目录结构是
    tagtest
    │  datetag.jsp

    └─WEB-INF
        │  web.xml
        │
        ├─classes
        │  └─com
        │      └─liad
        │          └─jsptaglibs
        │              └─date
        │                      DateTag.class
        │
        └─tlds
                simple.tld
      

  2.   

    是不是你的配置文件web.xml里面有问题。
    struts本身带的那些taglib用起来没有问题吗?
    假如要是没有问题,我想可能就是你的taglib有问题。
      

  3.   

    <b>可能<b/>是taglib-uri不对,作如下替换试试在你的机器上行不行:
     <taglib>
        <taglib-uri>/WEB-INF/page.tld</taglib-uri>
        <taglib-location>/WEB-INF/page.tld</taglib-location>
      </taglib>