0

我尝试编写有关自定义标签的演示代码,但是这个问题..我讨厌它,我可以自己解决它。

这是我的 .TLD 文件:

<tag>
    <name>custom</name>
    <tagclass>MyTag.CustomerTag</tagclass>
    <bodycontent>empty</bodycontent>
</tag>

这是我的班级 CustomerTag:

public class CustomerTag extends TagSupport {

    private PageContext _pageContext;

    @Override
    public int doStartTag() throws JspException {
        try {
            _pageContext.getOut().println("kakaka"); <-- **here cause exception**
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
        return SKIP_BODY;
    }

    @Override
    public int doEndTag() throws JspException {
        return SKIP_PAGE;
    }
}

这是我的 JSP 文件:

<%@taglib uri="/WEB-INF/Marko.tld"  prefix="myTag" %>
<myTag:custom />

请帮助我,谢谢大家

4

1 回答 1

1

In your code you are defining a separate _pageContext field that you never initialize; however, by extending TagSupport you should have access to a field pageContext that JSP initializes for you automatically.

Try removing the variable declaration and calling pageContext.getOut().println("kakaka"); instead.

于 2012-11-09T04:50:40.660 回答