I’m trying to build a common class for my JSP TagLib classes
I have
class MyTag extends CustomTag
{
public int doEndTag()
{
JspWriter out = pageContext.getOut(); <-- this one works fine
}
}
class CustomTag extends BodyTagSupport
{
public CustomTag()
{
JspWriter out = pageContext.getOut(); <-- this one throws me a Nullpointer
}
}
What am I doing wrong?
I could create a extra method in the parent and call it from the child from doEndTag() but it would be much nicer with the Constructor.
In the first class by the time
doEndTag()is called, thepageContexthas been set. In your second class,pageContexthas not been set and therefore isnull. That is what is causing your null pointer exception.See here for more details.