惊人: Servlet.service() for servlet jsp threw exception
严重: Servlet.service() for servlet jsp threw exception
at org.apache.jsp.indexjsp.jspInit(indexjsp.java:23)
环境:Tomcat6 + jdk6
Tomcat服务启动成功,但访问index.jsp出错,Tomcat报错如下:
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.indexjsp.jspInit(indexjsp.java:23)
at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:159)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.(HttpServlet.java:717)
at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
at orre.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at orre.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at orre.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at orre.StandardContextValve.invoke(StandardContextValve.java:191)
at orre.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at orre.StandardEngineValve.invoke(StandardEngineValve.java:109)
at ornnector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at oryote.(Http11AprProcessor.java:861)
at oryote.$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apach.AprEndpoint$Worker.run(AprEndpoint.java:1584)
at java.lang.Thread.run(Thread.java:619)
最后找到原因:jsp-api.jar冲突。
jsp-api.jar冲突会造成jsp页面无法解析。
写自定义标签的时候请注意,在工程编译的时候可以引用jsp-api.jar,但发布的时候工程不要包含此包,因为Tomcat已包含。
用于开发,而不用于发布
解决方法1:User Library
选中项目->右击->properties->Java Build Path -> Add Library -> 选中 User Liberary ->
Next -> User Libraries... -> New ->一定要选中:System Library....(作为系统库像JDK一样)
-> Add Jars ->导入 与Tomcat冲突jar -> 选中jsp-jar
OK
解决方法2:修改配置
打开项目目录,编辑.classpath文件
将:<classpathentry kind="lib" path="/............/jsp-jar"/>
改:<classpathentry kind="con" path="/............/jsp-jar"/>
刷新项目
OK