我正在使用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)
请帮助我...
答案 0 :(得分:1)
在tld文件中,tag应该引用tld文件路径 例如,而不是PathGenerator 它应该是 /WEB-INF/Path-taglib.tld
答案 1 :(得分:0)
检查是否已将声明包含在jsp中
<%@ taglib uri="PathGenerator" prefix="path" %>