2012-09-25 88 views
1

我正在使用Eclipse JUNO IDE爲我的WEB應用程序構建自定義JSP標記。無法加載自定義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) 

煩請幫我...

回答

0

檢查你是否有包含在JSP中的聲明爲

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

在TLD文件,標籤應該是指TLD文件路徑 例如,而不是PathGenerator它應該是 /WEB-INF/Path-taglib.tld

相關問題