5

I have spring mvc application with dummy jsp page (named htmlcontent.jsp). The jsp contains just a string:

HalloText

and this is the entire content of the jsp. The controller looks as follow:

package springapp.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HtmlContentController {

    @RequestMapping("/htmlcontent.htm")
    public String view() {
        return "htmlcontent";
    }
}

The bean is added in my springapp-web.xml

<bean id="htmlcontent" class="springapp.web.HtmlContentController">

And the servlet mapping in my web.xml is defined as follow:

<servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

When i call following:

http://localhost:8080/spring-mvc-hsqldb/htmlcontent.htm

then i get an NullPointerException:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:536)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.NullPointerException
    org.apache.jsp.htmlcontent_jsp._jspInit(htmlcontent_jsp.java:22)
    org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
    org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:164)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:338)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.30 logs.

In catalina.out there isn't any stack trace for this error. When i try to change the URL to http://localhost:8080/spring-mvc-hsqldb/htmlcondsasdadastent.htm, then i get:

WARNUNG: No mapping found for HTTP request with URI [/spring-mvc-hsqldb/htmlcondsasdadastent.htm] in DispatcherServlet with name 'springapp'

So i think, that must be the right log file. Can someone give me a hint, what i'm doing wrong? And why is the null pointer stack trace not in the log file?

3
  • which version of tomcat is this? Commented Feb 3, 2011 at 13:12
  • If you mark the controller with @Controller then you don't need to register the bean in the springapp-web.xml. Can you post how you have configured your View Resolver? And I think the url you have to use is localhost:8080/htmlcontent.htm instead of the one you're using. Commented Feb 3, 2011 at 13:22
  • 1
    when i call localhost:8080/htmlcontent.htm, then i get 404 Error (The requested resource (/htmlcontent.htm) is not available.") Commented Feb 3, 2011 at 14:10

1 Answer 1

22
java.lang.NullPointerException
    org.apache.jsp.htmlcontent_jsp._jspInit(htmlcontent_jsp.java:22)

A NPE in _jspInit() method indicates classpath pollution with JSP libraries of a different and older versioned servletcontainer than the one you're currently running.

To fix this, you need to ensure that you do not have any servletcontainer specific libraries such as jsp-api.jar, servlet-api.jar, el-api.jar, etc in your webapp's /WEB-INF/lib and for sure not in JRE's JRE/lib and JRE/lib/ext.

Servletcontainer specific libraries belong in the servletcontainer itself (in Tomcat 6, they're inside the Tomcat/lib folder), you should not ever touch them and not have duplicates of them or a different servletcontainer anywhere in your classpath.

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

2 Comments

strange that sts template includes this jar`s. I had to delete them from pom.xml to make it work
@BalusC , Are there any blogs illustrate how to use and import the servletcontainer specific libraries and servletcontainer independent libraries? for example, import the javax.servlet:javax.servlet-api:3.1 jar, it's independent jar, only make it in provided socpe, but servlet-api.jar is equivalent/replacement of that in servletcontainer specific libraries? Are there any diagram/table list the comparison?

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.