无法使用TagSuppot为JSP编译类

时间:2016-06-20 09:21:41

标签: jsp servlets taglib custom-tags

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

  

HTTP状态500 - 无法为JSP编译类

Taglib包含如下: <%@ taglib prefix =“ex”uri =“customtags”%>

我做错了什么?

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

解决

2 个答案:

答案 0 :(得分:0)

<?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" %>

答案 1 :(得分:0)

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

  

SupressWarnings( “串行”)

在HelloTag类之前