为什么总是报空指针异常?

来源:1-11 Servlet获取表单数据

D布克

2016-02-16 23:38


二月 16, 2016 11:33:09 下午 org.apache.catalina.core.AprLifecycleListener init

信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Myeclipse2014\binary\com.sun.java.jdk7.win32.x86_64_1.7.0.u45\bin;D:\Myeclipse2014\plugins\com.genuitec.eclipse.easie.tomcat7.myeclipse_11.5.0.me201310302042\tomcat\bin

二月 16, 2016 11:33:09 下午 org.apache.coyote.AbstractProtocol init

信息: Initializing ProtocolHandler ["http-bio-8080"]

二月 16, 2016 11:33:09 下午 org.apache.coyote.AbstractProtocol init

信息: Initializing ProtocolHandler ["ajp-bio-8009"]

二月 16, 2016 11:33:09 下午 org.apache.catalina.startup.Catalina load

信息: Initialization processed in 857 ms

二月 16, 2016 11:33:09 下午 org.apache.catalina.core.StandardService startInternal

信息: Starting service Catalina

二月 16, 2016 11:33:09 下午 org.apache.catalina.core.StandardEngine startInternal

信息: Starting Servlet Engine: Apache Tomcat/7.0.30

二月 16, 2016 11:33:09 下午 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory D:\练习01\.metadata\.me_tcat7\webapps\ServletGetFormDemo

二月 16, 2016 11:33:10 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["http-bio-8080"]

二月 16, 2016 11:33:10 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["ajp-bio-8009"]

二月 16, 2016 11:33:10 下午 org.apache.catalina.startup.Catalina start

信息: Server startup in 701 ms

二月 16, 2016 11:34:22 下午 org.apache.catalina.core.ApplicationDispatcher invoke

严重: Servlet.service() for servlet jsp threw exception

java.lang.NullPointerException

at org.apache.jsp.userinfo_jsp._jspService(userinfo_jsp.java:162)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

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:722)

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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)

at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)

at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)

at com.imooc.servlet.RegServlet.doPost(RegServlet.java:96)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

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.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)

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:1002)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:744)

org.apache.jasper.JasperException: java.lang.NullPointerException

at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)

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:722)

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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)

at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)

at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)

at com.imooc.servlet.RegServlet.doPost(RegServlet.java:96)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

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.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)

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:1002)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)

at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:744)

Caused by: java.lang.NullPointerException

at org.apache.jsp.userinfo_jsp._jspService(userinfo_jsp.java:162)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)

... 27 more


写回答 关注

2回答

  • easontsui
    2016-02-17 18:00:32
    已采纳

    没做非空判断就取值或者取错对象了呗,检查下代码

    D布克

    非常感谢!

    2016-02-17 19:48:32

    共 1 条回复 >

  • D布克
    2016-02-17 22:03:20

    原来一直没有把u.setFavorites(favorites);这个值给传进去,太粗心啦

JAVA遇见HTML——Servlet篇

本门课程在JSP课程的基础上,深入介绍Servlet的基础知识

160613 学习 · 1029 问题

查看课程

相似问题