提问人:lemon805 提问时间:8/27/2021 最后编辑:lemon805 更新时间:9/19/2021 访问量:719
org.apache.catalina.core.ApplicationDispatcher 调用引发异常 java.lang.NullPointerException
org.apache.catalina.core.ApplicationDispatcher invoke threw exception java.lang.NullPointerException
问:
使用 Eclipse 进行 MVC,
- 如果以 开头,则列表效果很好。
com.controller.main/mainServlet.java
- 但是如果从 、 到 开始,则会出现此错误。
WebContect/main.jsp
Webcontent/goods/goodsList.jsp
在 Servlet 中,任一
请求调度程序 dis = request.getRequestDispatcher(“main.jsp”);
或
RequestDispatcher dis = request.getRequestDispatcher(“goods/goodsList.jsp”);,
无论如何,如果在 main.jsp 中启动,则会出现错误。
java.lang.NullPointerException
at org.apache.jsp.goods.goodsList_jsp._jspService(goodsList_jsp.java:139)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:713)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:583)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:519)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:865)
at org.apache.jsp.main_jsp._jspService(main_jsp.java:137)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:615)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
at org.apache.jsp.goods.goodsList_jsp._jspService(goodsList_jsp.java:139)
这部分就在这里。我真的很想知道......
<%
List<GoodsDTO> list = (List<GoodsDTO>)request.getAttribute("goodsList");
for( int i = 1; i <= list.size(); i++ ){
GoodsDTO dto = list.get(i+1);
String gCode = dto.getgCode();
String gCategory = dto.getgCategory();
String gName = dto.getgName();
String gContent = dto.getgContent();
int gPrice = dto.getgPrice();
String gImage = dto.getgImage();
%>
答:
0赞
bogatov
9/19/2021
#1
我不知道您启动应用程序的两种方式之间的区别,但从您的逻辑来看,这部分:List<GoodsDTO>
for( int i = 1; i <= list.size(); i++ ){
GoodsDTO dto = list.get(i+1);
应该抛出 IndexOutOfBoundException。当您增加到 然后 do 时,它将超出列表大小。如果以 开头,应该可以帮助您避免它。
也许这与您得到的 NPE 有某种联系?但是奇怪的是,当您从列出的第一种方法开始时,它会起作用。i
list.size
list.get(i+1)
i=1
list.get(i-1)
评论