【发布时间】:2016-10-21 11:47:00
【问题描述】:
我正在尝试使用标签支持来使用我自己的标签。但是当我加载我的页面时,会发生以下错误:
HTTP 状态 500 - 无法为 JSP 编译类
Taglib 包含如下:
我做错了什么?
<jsp-config>
<taglib>
<taglib-uri>customtags</taglib-uri>
<taglib-location>WEB-INF/tags/custom.tld</taglib-location>
</taglib>
</jsp-config>
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>ctg</short-name>
<uri>customtags</uri>
<tag>
<name>info-time</name>
<tag-class>by.epam.customtags.HelloTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
public class HelloTag extends TagSupport {
@Override
public int doStartTag() throws JspException {
GregorianCalendar gc = new GregorianCalendar();
String time = "<hr/>Time : <b> " + gc.getTime() + " </b><hr/>";
String locale = "Locale : <b> " + Locale. getDefault() + " </b><hr/> ";
try {
JspWriter out = pageContext.getOut();
out.write(time + locale);
} catch (IOException e) {
throw new JspException(e.getMessage());
}
return SKIP_BODY;
}
@Override
public int doEndTag() throws JspException {
return EVAL_PAGE;
}
}
更新:通过添加 SupressWarnings("serial") 解决
【问题讨论】:
标签: jsp servlets taglib custom-tags