我收到错误“HtmlEncoderTag 无法解析为类型”关于定义自定义标签?
我正在定义一个自定义标签“htmlencoder”。我有这些文件:
WEB-INF/classes/HtmlEncoderTag.jar ,带有如下 java 代码:
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class HtmlEncoderTag extends BodyTagSupport{
//....
}
WEB-INF/htmlencoder.tld :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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>1.2</jsp-version>
<short-name></short-name>
<tag>
<name>htmlencode</name>
<tag-class>HtmlEncoderTag</tag-class>
<body-content>JSP</body-content>
</tag>
</taglib>
index.jsp:
<%@ taglib uri="WEB-INF/htmlencoder.tld" prefix="htmlencoder"%>
<head>
<title>Watch out you sinners...</title>
</head>
<html>
<body bgcolor="white">
<htmlencoder:htmlencode><script <% //the error refers to this line %>
type="javascript">BadStuff()</script></htmlencoder:htmlencode>
</body>
</html>
当我运行时收到错误“HtmlEncoderTag 无法解析为类型”我的页面,它显示了 index.jsp:7 行(我上面提到过)。
我应该怎么办?
I am defining a custom tag "htmlencoder". I have These files:
WEB-INF/classes/HtmlEncoderTag.jar ,with a java code like this:
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class HtmlEncoderTag extends BodyTagSupport{
//....
}
WEB-INF/htmlencoder.tld :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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>1.2</jsp-version>
<short-name></short-name>
<tag>
<name>htmlencode</name>
<tag-class>HtmlEncoderTag</tag-class>
<body-content>JSP</body-content>
</tag>
</taglib>
index.jsp:
<%@ taglib uri="WEB-INF/htmlencoder.tld" prefix="htmlencoder"%>
<head>
<title>Watch out you sinners...</title>
</head>
<html>
<body bgcolor="white">
<htmlencoder:htmlencode><script <% //the error refers to this line %>
type="javascript">BadStuff()</script></htmlencoder:htmlencode>
</body>
</html>
I got the error "HtmlEncoderTag cannot be resolved to a type" when i run my page and it shows me the line index.jsp:7 ( I mentioned above).
What should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了答案。我不确定这是必要的,但我的问题是这样解决的:
您必须将标记类放入包中。例如,您的 HtmlEncoderTag.jar 文件应放置在 WEB-INF/MyTag/ 中,并且应如下所示:
您的 tld 文件将如下所示:
I found the answer. I'm not sure it is necessary, but my problem solved this way:
You have to put your tag class in a package. for example, your HtmlEncoderTag.jar file should be placed in WEB-INF/MyTag/ and should be like this:
And your tld file will be like this:
有两件事:
Two things: