I have never worked with taglibs, but...

Your NullPointerException can only be caused because pageContext is null.

Can you access the pageContext (I understand it must be a field from TagSupport) *before* doStartTag() is called?

You can try moving that line to be the first line *inside* the method.

Just a very wild guess.



Antonio Fiol


Werner van Mook wrote:

Hi all,

I created a jsp with this tag :

<ina:displayResponse />

I included a taglib directive and did all things I should do to get it working.

The class for this tag is :

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

import util.Message;

public class DisplayResponse extends TagSupport {

// The next line is line 54
Enumeration e = pageContext.getAttributeNamesInScope(PageContext.REQUEST_SCOPE);

    public int doStartTag() throws JspException {
        JspWriter out = pageContext.getOut();

try { if(e.hasMoreElements()) {
out.println((String)e.nextElement());
} else {
out.println("It has no more elements.");
}
out.println("Just transformed o into message.");
} catch (IOException ioe) {
ioe.printStackTrace();
}
return SKIP_BODY;
}
}

If I run this I get a nullPointerException on the line defining the enumeration.
see :


javax.servlet.ServletException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageCont extImpl.java:864)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContex tImpl.java:800)
org.apache.jsp.view_jsp._jspService(view_jsp.java:67)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja va:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: 301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


root cause
java.lang.NullPointerException
tags.DisplayResponse.(DisplayResponse.java:54)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorA ccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingCons tructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:274)
java.lang.Class.newInstance0(Class.java:308)
java.lang.Class.newInstance(Class.java:261)
org.apache.jasper.runtime.TagHandlerPool.get(TagHandlerPool.java:161)
org.apache.jsp.view_jsp._jspx_meth_ina_displayResponse_0(view_jsp.java: 78)
org.apache.jsp.view_jsp._jspService(view_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja va:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: 301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


If I would change it to someting like :

Enumeration e = ((HttpServletRequest)pageContext.getRequest()).getAttributeNames();
I get the expected result.
see :

message Just transformed o into message.


According to the docs getAttributeNamesInScope can only throw : java.lang.IllegalArgumentException or java.lang.IllegalStateException


So is this a bug? Or did I miss something?



Werner van Mook
Java Lead Developer / Trainer
Connecties Voor Internet



Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to