org.apache.jsp.index_jsp._jspInit 处的 java.lang.NullPointerException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13892810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:20:57  来源:igfitidea点击:

java.lang.NullPointerException at org.apache.jsp.index_jsp._jspInit

javajspjsftomcatservlets

提问by chetan

When i try to run project deployed inside tomcat i get error like

当我尝试运行部署在 tomcat 中的项目时,我收到类似的错误

java.lang.NullPointerException
    at org.apache.jsp.index_jsp._jspInit(index_jsp.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.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
    at java.lang.Thread.run(Thread.java:619)

I have searched regarding that and found that it might be problem of servlet-api.jar and jsp-api.jar but i have copied both from tomcat to my project's classpath still i am getting the same error.

我已经搜索过,发现它可能是 servlet-api.jar 和 jsp-api.jar 的问题,但我已经将它们从 tomcat 复制到我的项目的类路径中,但我仍然遇到相同的错误。

Jsp :

:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
     <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    --> 
  </head>

  <body>
    <%--<a href="login.iface">Click Here</a> --%>
  </body>
</html>

classpath contain following list of jar

类路径包含以下 jar 列表

antlr-2.7.6
commons-beanutils
commons-collections
commons-collections-3.1
commons-digester
commons-logging
commons-logging-1.1
dom4j-1.6.1
ejb3-persistence
hibernate3
hibernate-annotations
hibernate-commons-annotations
icefaces-1.8.2
icefaces-comps-1.8.2
javassist-3.9.0.GA
jsf-api
jsf-facelets
jsf-impl
mysql-connector-java-3.1.8-bin
slf4j-api-1.5.11
slf4j-simple-1.5.11

回答by BalusC

I have searched regarding that and found that it might be problem of servlet-api.jar and jsp-api.jar but i have copied both from tomcat to my project's classpath

我已经搜索过,发现它可能是 servlet-api.jar 和 jsp-api.jar 的问题,但我已将它们从 tomcat 复制到我的项目的类路径

It look like that you misunderstood the answers. Having them in your webapp's runtime classpath (WEB-INF/lib) isthe whole cause of this problem! Get rid of them.

看起来你误解了答案。将它们放在 Web 应用程序的运行时类路径 (WEB-INF/lib) 中导致此问题的全部原因!摆脱他们。

The servletcontainer itself alreadyships with those libraries out the box. Providing randomly downloaded libraries from an arbitrary container of a possibly different make/version along with the webapp would only lead to this kind of problems. If you did this in order to "fix" compilation errors in your webapp project, then you should have solved it differently. See the below links for the how:

servletcontainer 本身已经附带了这些库。从可能不同品牌/版本的任意容器中提供随机下载的库以及 web 应用程序只会导致此类问题。如果您这样做是为了“修复”您的 webapp 项目中的编译错误,那么您应该以不同的方式解决它。有关方法,请参阅以下链接:

See also:

也可以看看: