我已经创建了一个自定义标记但是当我使用以下异常时: -
An error occurred at line: 14 in the jsp file: /index.jsp
LoopTextTag cannot be resolved to a type
<body>
<center>
<ct:loopText times="5">
<h3>Loop Text!</h3>
</ct:loopText>
堆栈跟踪:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
我的LoopTaxtTag类如下:
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class LoopTextTag extends BodyTagSupport {
private static final long serialVersionUID = 1L;
private int mTimes = 0;
private BodyContent mBodyContent;
public void setTimes(int pTimes) {
mTimes = pTimes;
}
public void setBodyContent(BodyContent pBodyContent) {
mBodyContent = pBodyContent;
}
@SuppressWarnings("deprecation")
public int doStartTag() throws JspException {
if (mTimes > 1) {
return EVAL_BODY_TAG;
} else {
return SKIP_BODY;
}
}
@SuppressWarnings("deprecation")
public int doAfterBody() throws JspException {
if (mTimes > 1) {
mTimes--;
return EVAL_BODY_TAG;
} else {
return SKIP_BODY;
}
}
public int doEndTag() throws JspException {
try {
if (mBodyContent != null) {
mBodyContent.writeOut(mBodyContent.getEnclosingWriter());
}
} catch (IOException pIOEx) {
throw new JspException("Error: " + pIOEx.getMessage());
}
return EVAL_PAGE;
}
}
我的index.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="com.pt.LoopTextTag"%>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="ct" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
< %@ taglib uri="/WEB-INF/custom.tld" prefix="ct" %>
</head>
<body>
<center>
<ct:loopText times="5">
<h3>Loop Text!</h3>
</ct:loopText>
</center>
</body>
编译器也提出警告:
The tag handler class for "ct:loopText" (LoopTextTag) was not found on the Java Build Path
答案 0 :(得分:0)
如果你还没弄明白,问题出在index.jsp
的下一行:
< %@ taglib uri="/WEB-INF/custom.tld" prefix="ct" %>
uri
此处应与<uri>
文件中提到的tld
标记相匹配。 tld
文件应位于容器查找的以下位置之一:
希望这有帮助