1

In my servlet I do:

request.getRequestDispatcher("/page.jsp").forward(request,response);

I get the following NullPointerException on Tomcat 6, but it works in Tomcat 7.

SEVERE: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException
    at org.apache.jsp.page_jsp._jspInit(page_jsp.java:23)
    at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:159)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at com.dotvocal.poa.vocal.main.servlet.LoadCompany.execute(MyServlet.java:100)
    at com.dotvocal.poa.vocal.main.servlet.LoadCompany.doGet(MyServlet.java:60)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

I also tried the following:

request.getRequestDispatcher("http://localhost:8080/myapp/page.jsp").forward(request,response);

But it didn't solve the problem.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1611777
  • 39
  • 1
  • 1
  • 7
  • 3
    can you please provide more information about your problem ? like the full message in the log not just the "hullpointerexception" part – Jorge Aguilar Aug 30 '12 at 14:39
  • 1
    You will have to be more specific (i.e. full stack trace, code snippets of the lines that are causing the NullPointerException, etc) – Raul Rene Aug 30 '12 at 14:40

2 Answers2

2

java.lang.NullPointerException at org.apache.jsp.page_jsp._jspInit(page_jsp.java:23)

You have servletcontainer-specific JSP libraries such as jsp-api.jar in your webapp's /WEB-INF/lib or maybe JDK/lib or JDK/lib/ext.

Remove them. They don't belong there at all. The servletcontainer itself already ships with those libraries. Based on the problem symptoms, the one which you've in your webapp originated from Tomcat 7 and thus your webapp will fail to work when you deploy it to a different servletcontainer make/version such as Tomcat 6, because it would conflict with servletcontainer's own libraries.

Erroneously placing servletcontainer-specific libraries in webapp's /WEB-INF/lib is a classic starter's mistake in a wrong attempt to fix Servlet API compilation errors in the IDE project. You should instead reference the servletcontainer as "target runtime" in the IDE project.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    removed jsp-api.jar and servlet-api.jar from /lib. Referenced the servletcontainer as "target runtime". Now it works. Thank you :) – user1611777 Aug 30 '12 at 15:22
0

I had the same error using JBoss 4.3, my solution was deleting the log, work and tmp folder from my JBoss enviroment.

  • Could you please elaborate more your answer adding a little more description about the solution you provide? – abarisone Sep 18 '15 at 11:47