org.apache.jsp.foo_jsp._jspInit(foo_jsp.java:22)中的java.lang.NullPointerException

时间:2011-02-03 12:33:50

标签: jsp tomcat nullpointerexception

我有一个带有虚拟jsp页面的spring mvc应用程序(名为htmlcontent.jsp)。 jsp只包含一个字符串:

HalloText

这是jsp的全部内容。控制器如下所示:

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";
    }
}

将bean添加到我的springapp-web.xml

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

我的web.xml中的servlet映射定义如下:

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

当我打电话给跟随时:

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

然后我得到一个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.

在catalina.out中,此错误没有任何堆栈跟踪。当我尝试将网址更改为http://localhost:8080/spring-mvc-hsqldb/htmlcondsasdadastent.htm时,我得到:

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

所以我认为,那必须是正确的日志文件。有人可以给我一个暗示,我做错了什么?为什么空指针堆栈跟踪不在日志文件中?

1 个答案:

答案 0 :(得分:22)

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

_jspInit()方法中的NPE表示使用与当前正在运行的servlet容器不同且版本较旧的servlet容器的JSP库的类路径污染。

要解决此问题,您需要确保在您的<{1}},jsp-api.jarservlet-api.jar等中包含任何servletcontainer特定库。 webapp的el-api.jar肯定不在JRE的/WEB-INF/libJRE/lib

Servletcontainer特定库属于servletcontainer本身(在Tomcat 6中,它们位于JRE/lib/ext文件夹中),您不应该触摸它们,也不要在它们的类路径中的任何位置具有它们的副本或不同的servlet容器。