Question

I try to code demo about custom tag , but this problem .. I hate it, I can solve it by my self.

here is my .TLD file:

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

And here is my class 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;
    }
}

Here is my JSP file:

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

Please help me, thanks everyone

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top