我有带有伪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,我得到:
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'
所以我认为,那一定是正确的日志文件。有人可以提示我,我做错了吗?为何空指针堆栈跟踪不在日志文件中?
java.lang.NullPointerException org.apache.jsp.htmlcontent_jsp._jspInit(htmlcontent_jsp.java:22)
NPE in _jspInit()方法指示与当前运行的servlet容器不同和较旧版本的servlet容器的JSP库导致类路径污染。
_jspInit()
为了解决这个问题,你需要确保你 不会 有任何servletcontainer特定的库如jsp-api.jar,servlet- api.jar,el-api.jar,在你的webapp的等/WEB- INF/lib,并肯定不是在JRE的JRE/lib和JRE/lib/ext。
jsp-api.jar
servlet- api.jar
el-api.jar
/WEB- INF/lib
JRE/lib
JRE/lib/ext
特定于Servletcontainer的库属于servletcontainer本身(在Tomcat 6中,它们位于Tomcat/lib文件夹内),您永远不要触摸它们,并且在类路径中的任何地方都不要重复使用它们或其他servletcontainer。
Tomcat/lib