Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

tomcat - java.lang.NullPointerException at org.apache.jsp.foo_jsp._jspInit(foo_jsp.java:22)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...