org.apache.jsp.foo_jsp._jspInit(foo_jsp.java:22) 处的 java.lang.NullPointerException
我有带有虚拟 jsp 页面(名为 htmlcontent.jsp)的 spring mvc 应用程序。 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 中没有此错误的任何堆栈跟踪。当我尝试将 URL 更改为 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'
所以我认为,这一定是正确的日志文件。有人可以给我提示,我做错了什么吗?为什么空指针堆栈跟踪不在日志文件中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
_jspInit()
方法中的 NPE 表示与当前运行的 servlet 容器不同且旧版本的 servlet 容器的 JSP 库存在类路径污染。要解决此问题,您需要确保您没有有任何 servletcontainer 特定的库,例如
jsp-api.jar
、servlet-api.jar
、el-api.jar
等位于 Web 应用程序的/WEB-INF/lib
中,并且肯定不在 JRE 的JRE/lib
和 <代码>JRE/lib/ext。Servletcontainer 特定的库属于 servletcontainer 本身(在 Tomcat 6 中,它们位于
Tomcat/lib
文件夹内),您不应该碰它们,也不应该在您的任何地方有它们的重复项或不同的 servletcontainer类路径。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'sJRE/lib
andJRE/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.