1

我正在使用 Eclipse JUNO IDE 为我的 WEB 应用程序构建自定义 JSP 标记。

但是 Eclipse 并没有在 /WEB-INF/classes 目录中为该 TagHandler 生成 .class 文件,而是为其他 java 文件生成。

这是下面的代码,如果您可以查看它。

PathTagHandler.java

package fna.handlers;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class PathTagHandler extends TagSupport {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

private String compName = null;

    private String filingYear=null;


    public String getCompName() {
        return compName;
    }
    public void setName(String aName) {
        this.compName = aName;
    }

    public String getFilingYear() {
        return filingYear;
    }
    public void setFilingYear(String aYear) {
        this.filingYear = aYear;
    }

    public int doStartTag() throws JspTagException {
        try{
            JspWriter out = pageContext.getOut();
            if(compName != null && filingYear!=null){
                out.print(get10KPath(compName, filingYear));
            }else{
                out.print("Please provide required params in the tag!!!");
            }
        }catch(IOException ioe){
            ioe.printStackTrace();
        }
        return SKIP_BODY;
    }


    private static String get10KPath(String comp, String year){

        String path="htmlDocs/";

        String compName=comp.trim().toLowerCase();

        path.concat(compName).concat("/").concat(year).concat("/").concat("10k.html");

        return path;

    }

   @Override  
   public int doEndTag() throws JspException {  
       // TODO Auto-generated method stub  
       //return super.doEndTag();  
       return EVAL_PAGE;  
   }  

}

文件路径-taglib.tld

<?xml version="1.0" encoding="UTF-8"?>
<!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>2.1</jsp-version>
    <short-name>MyLibrary</short-name>
    <uri>PathGenerator</uri> 
    <tag>
    <name>10kPath</name>
    <tag-class>fna.handlers.PathTagHandler</tag-class>
    <attribute>
      <name>compName</name>
      <required>true</required>
  </attribute>
    <attribute>
      <name>filingYear</name>
      <required>true</required>
  </attribute>
</tag>
</taglib> 

web.xml

<jsp-config> 
 <taglib>
    <taglib-uri>PathGenerator</taglib-uri>
    <taglib-location>/WEB-INF/filePath-taglib.tld</taglib-location>
 </taglib>
 </jsp-config>

我得到的错误如下所述:

org.apache.jasper.JasperException: /Test.jsp(47,1) Unable to load tag handler class "fna.handlers.PathTagHandler" for tag "path:10kPath"
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:198)
    org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1194)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1418)
    org.apache.jasper.compiler.Parser.parse(Parser.java:130)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:185)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:347)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

请帮助我...

4

2 回答 2

1

例如,在 tld 文件中,标记应引用 tld 文件路径,而不是 PathGenerator,它应为 /WEB-INF/Path-taglib.tld

于 2014-09-02T07:20:46.193 回答
0

检查您是否已在 jsp 中包含声明为

    <%@ taglib uri="PathGenerator" prefix="path" %>
于 2013-07-17T07:18:48.813 回答