java.lang.NullPointerException at org.apache.jsp.index_jsp._jspInit(index_jsp.ja
java.lang.NullPointerExceptionatorg.apache.jsp.index_jsp._jspInit(index_jsp.ja
环境:Tomcat6+jdk6
Tomcat服务启动成功,但访问index.jsp出错,Tomcat报错如下:
严重:Servlet.service()forservletjspthrewexception
java.lang.NullPointerException
atorg.apache.jsp.index_jsp._jspInit(index_jsp.java:23)
atorg.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52)
atorg.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:159)
atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
atjavax.servlet.http.HttpServlet.service(HttpServlet.java:717)
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
atorg.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:389)
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
atjava.lang.Thread.run(Thread.java:619)
最后找到原因:jsp-api.jar冲突。
jsp-api.jar冲突会造成jsp页面无法解析。
写自定义标签的时候请注意,在工程编译的时候可以引用jsp-api.jar,但发布的时候工程不要包含此包,因为Tomcat已包含。
用于开发,而不用于发布
解决方法1:UserLibrary
选中项目-->右击-->properties-->JavaBuildPath-->AddLibrary-->选中UserLiberary-->
Next-->UserLibraries...-->New-->如下一定要选中:口SystemLibrary....(作为系统库像JDK一样)
-->AddJars-->导入与Tomcat冲突jar-->选中jsp-jarOK
解决方法2:修改配置
打开项目目录,编辑.classpath文件
将:<classpathentrykind="lib"path="/............/jsp-jar"/>
改:<classpathentrykind="con"path="/............/jsp-jar"/>
刷新项目OK
结果导入的jar包显示为系统库: