无法加载自定义JSP标记处理程序类

brc7rcf0  于 2023-03-21  发布在  其他
关注(0)|答案(3)|浏览(171)

我正在使用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;  
   }  

}

filePath-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)

请帮帮我...

iyr7buue

iyr7buue1#

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

elcex8rz

elcex8rz2#

检查是否已将声明作为

<%@ taglib uri="PathGenerator" prefix="path" %>
kx5bkwkv

kx5bkwkv3#

你必须将JSTL jar文件添加到你的项目库文件夹中。

相关问题