无法使用TagSuppot编译JSP的类



我正在尝试使用标签支持来我们自己的标签。但是,当我加载页面时,会发生以下错误:

HTTP状态500-无法编译JSP

的类

taglib这样包含在内:<%@ taglib prefix =" ex" uri =" fastertags"%>

我在做什么错?

<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")

来解决

<?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>
   <jsp-version>2.0</jsp-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>
And use direct reference in the jsp as
<%@ taglib prefix="ex" uri="WEB-INF/tags/custom.tld" %>

我解决了它!问题是我添加

supresswarnings(" serial")

在Hellotag类之前

最新更新