Java 这是 Apache Tomcat 的标准错误吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18589715/
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
Is this a standard error from Apache Tomcat?
提问by abierto
I'm receiving this error while accessing in the index page of my JSP project.
我在 JSP 项目的索引页中访问时收到此错误。
Sep 3, 2013 12:03:14 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/MyProject] threw exception [java.lang.NullPointerException] with root
cause
java.lang.NullPointerException
at org.apache.jsp.index_jsp._jspService(index_jsp.java:126)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
I guess this is a "standard error" from TomCat but I can't find out what is the real problem.
我想这是来自 TomCat 的“标准错误”,但我无法找出真正的问题是什么。
采纳答案by Anders R. Bystrup
It's a java.lang.NullPointerException
in your JSP page, but I take it you'd figured that out already.
它java.lang.NullPointerException
在您的 JSP 页面中,但我认为您已经知道了。
JSP pages are converted/compiled to Java - thus the (index_jsp.java:126)
in the stacktrace - but unfortunately you can't use the line number for figuring out the problem as it doesn't relate to your JSP file, but the resulting Java source.
JSP 页面被转换/编译为 Java - 因此(index_jsp.java:126)
在堆栈跟踪中 - 但不幸的是,您不能使用行号来找出问题,因为它与您的 JSP 文件无关,而是与生成的 Java 源代码相关。
You should, however, be able to figure out where the NPE happens by inspection, since your JSP is of course a thin presentation layer, right :-) A usual mistake could be referencing attributes that aren't provided on entry to the page, eg. request.getParameter( "something" ).equals( "somethingelse" )
<-- possible NPE on .equals()
但是,您应该能够通过检查找出 NPE 发生的位置,因为您的 JSP 当然是一个薄的表示层,对 :-) 一个常见的错误可能是引用了页面入口处未提供的属性,例如。request.getParameter( "something" ).equals( "somethingelse" )
<-- 可能的 NPE.equals()
If you were to share the JSP page (perhaps in the form of an SSCCE), this community can help much better.
如果您要共享 JSP 页面(可能以SSCCE的形式),这个社区可以提供更好的帮助。
Cheers,
干杯,
回答by Aneesh
It's not a "Tomcat standard" error. Its an error in your source code. JSP is translated to java and java.lang.NullPointerException
signifies that somewhere you are trying to use some variable without properly initializing it. Or you may have expected it to be initialized but it hasn't due to some resource being unavailable.
这不是“Tomcat 标准”错误。它是您的源代码中的错误。JSP 被转换为 java 并java.lang.NullPointerException
表示您在某处尝试使用某个变量而没有正确初始化它。或者您可能希望它被初始化,但由于某些资源不可用而没有初始化。
回答by user1505070
You CAN use the line number to find the error. (The answer by Anders R. Bystrup incorrectly says the opposite "...unfortunately you can't use the line number for figuring out the problem".)
您可以使用行号来查找错误。(Anders R. Bystrup 的回答错误地指出了相反的“......不幸的是,您不能使用行号来找出问题”。)
It's true the JSP pages are converted to Java and thus the line number does not correspond to the line number in your JSP, but you can find the converted Java file in your work directory, somewhere like:
JSP 页面确实被转换为 Java,因此行号与 JSP 中的行号不对应,但您可以在工作目录中找到转换后的 Java 文件,例如:
${TOMCAT_HOME}/work/Catalina/localhost/_/org/apache/jsp/index_jsp.java
and looking at the given line number (126) in that file should point you toward the problem in your JSP (there will likely be an identical line in your JSP).
并查看该文件中给定的行号 (126) 应该将您指向 JSP 中的问题(您的 JSP 中可能有相同的行)。
As others have already pointed out, in this case you have an NPE.
正如其他人已经指出的那样,在这种情况下,您有一个 NPE。