org.apache.jsp.orderOnline_jsp._jspService中的java.lang.NullPointerException

时间:2016-05-19 03:49:30

标签: java nullpointerexception

我正在编写一个包含sql数据库的简单网站。 每当我尝试从数据库中获取数据时,我都会收到以下错误

enter image description here

使用以下日志

====

WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at org.apache.jsp.orderOnline_jsp._jspService(orderOnline_jsp.java from :125)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:695)

我相信我的一个页面中的以下代码会出现错误

OrderOnline.jsp

<%
    ArrayList al=(ArrayList)request.getAttribute("allMenu");
    for(int i=0; i<al.size(); i++)
    {
      Menu menu = (Menu)al.get(i);
      %>
      <div class="row" style="color: #fff; padding-top: 30px;font-size: 20px;text-align: center">
      <div class="col-sm-2"><%=menu.getName() %></div>
      <div class="col-sm-1" style="color: gold"><%="$"+menu.getPrice() %></div>
      <div class="col-sm-4"><%=menu.getDes() %></div>
      <div class="col-sm-2"></div>
      <div class="col-sm-2"><a href="OrderCL?type=add&id=<%=menu.getId()+"" %>"><button type="button" class="btn btn-default">Want Me</button></a></div>
      <div class="col-sm-1"></div>
      <%
        }
%>

有人可以帮忙解决这个问题吗?

我附上了项目的链接。 因此,您可以使用glassFish Server 3.1在netbeen上运行它

使用现有资源创建新的JAva Web项目

https://www.dropbox.com/s/xgd1vsu0wjvykfl/star-2016-05-18.zip?dl=0

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您的ArrayList al必须为null。 请检查您是否在请求范围中存储了名为“allMenu”的属性。