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.

2
  • 3
    can you please provide more information about your problem ? like the full message in the log not just the "hullpointerexception" part Commented Aug 30, 2012 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) Commented Aug 30, 2012 at 14:40

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

1 Comment

removed jsp-api.jar and servlet-api.jar from /lib. Referenced the servletcontainer as "target runtime". Now it works. Thank you :)
0

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

1 Comment

Could you please elaborate more your answer adding a little more description about the solution you provide?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.