将你的xxx.tld文件放入
%TOMCAT%webapps/tgglib/
目录下,然后修改
%TOMCAT%webapps/tgglib/WEB-INF/web.xml
文件,加入
<taglib>
  <taglib-uri>http://www.mylib.com/testlib</taglib-uri>
  <taglib-location>/xxx.tld</taglib-location>
</taglib>
在jsp文件里申明
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ taglib uri="http://www.mylib.com/testlib" prefix="test"%>
如下试分别调用xxx.tld里定义的两个标记类
<test:readInterestType />
<test:calcInterest yearName="" principalName="" interestName="" balanceName="">
  taglib content!
</test:calcInterest>

解决方案 »

  1.   

    兄弟门请指点啊,<%@ taglib uri="http://www.mylib.com/testlib" prefix="test"%>
    楼上的老兄这个uri是怎么回事啊,能不能给讲解一下,我刚才给你发了短信一直都在等你的消息呢,大概你老兄休息了吧,谁能告诉我uri具体怎么写?还有个问题是,我的html页面调用本来是没问题的,但如果修改成用taglib实现就出现找不到html文件的错误,到底是怎么回事,难道跟web.xml中布置标签关系紧密,谁能告诉我是对还是错!!!
      

  2.   

    When the JSP engine parses a JSP file and encounters a taglib directive, it checks its
    taglib map to see if a mapping exists for the uri attribute of the taglib directive:
    &#8226; If the value of the uri attribute matches any of the <taglib-uri> entries,
    the engine uses the value of the corresponding <taglib-location> to
    locate the actual TLD file.
    &#8226; If the <taglib-location> value is a root-relative URI (that is, it starts
    with a /), the JSP engine assumes the location to be relative to the web
    application’s document root directory. Thus, the location for the URI
    http://www.manning.com/studyKit in listing 15.1 will resolve to
    the TLD file <doc-root>/myLibs/studyKit.tld.
    &#8226; If the <taglib-location> value is a non-root relative URI (that is, it
    starts without a /), the JSP engine prepends /WEB-INF/ to the URI and
    assumes the location to be relative to the web application’s document root
    directory. Thus, the location for the URI http://www.manning.com/
    sample.jar in listing 15.1 will resolve to the TLD file <doc-root>/
    WEB-INF/yourLibs/studyKit.tld.
    &#8226; If the value of the uri attribute of the taglib directive does not match any of
    the <taglib-uri> entries, then the following three possibilities arise:
    &#8226; If the specified uri attribute is an absolute URI, then it is an error and is
    reported at translation time.
    &#8226; If the specified uri attribute is a root-relative URI, it is assumed to be relative
    to the web application’s document root directory.
    &#8226; If the specified uri attribute is a non-root-relative URI, it is assumed to be
    relative to the current JSP page. Thus, if the JSP file <doc-root>/jsp/
    test.jsp contains the directive <%@ taglib prefix="test"
    uri="sample.tld" %>, the engine will expect to find the sample.tld
    file at <doc-root>/jsp/sample.tld.
      

  3.   

    给你一个最简单的例子,来自《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>
      

  4.   

    用dos命令tree /f获得的目录结构是
    tagtest
    │  datetag.jsp

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

  5.   

    标记库编好后在web-inf下建一个tlds文件夹,标记库文件(*.tld)就放在那个文件夹下!
      

  6.   

    to liad 
    我按你的例子做下来,运行是出现以下错误,请问是什么问题
    org.apache.jasper.JasperException: Unable to initialize TldLocationsCache: zip file closed