users@glassfish.java.net

_at_EJB DI - NullPointer Exception

From: <glassfish_at_javadesktop.org>
Date: Wed, 18 Apr 2007 21:30:50 PDT

Hello All,

I have this as follows which works in my machine at work. But the same codes with same set of environment results in nullpointer exception. can anyone point out what might have been wrong here?

public class HelloServlet extends HttpServlet {
    @EJB
    private HelloLocal hello;
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String name = request.getParameter("name");
        
        out.println(hello.sayHello(name)); //this is what throws nullpointer
 
        out.close();
    }
   
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
}

Exception:
StandardWrapperValve[HelloServlet]: Servlet.service() for servlet HelloServlet threw exception
java.lang.NullPointerException
        at web.HelloServlet.processRequest(HelloServlet.java:43)

thanks,
TR
[Message sent by forum member 'rayt' (rayt)]

http://forums.java.net/jive/thread.jspa?messageID=213070