StandardWrapperValve[debugjsp]: Servlet.service() for servlet debugjsp threw exception
java.lang.NullPointerException
at org.apache.jsp.zhongyibu.wjhb_005fnr_jsp._jspService(wjhb_005fnr_jsp.java:113)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
以上说是出现空指针异常,但代码
int id;
try {
id = Integer.parseInt(request.getParameter("id"));
} catch (NumberFormatException e) {
id = 0;
}
已经对此处进行捕捉,问题不是出于上面代码。
关键是id参数的值真正存在于数据库对应的ID值吗?
CD CD=dao.findCD(id);
假如经过
int id;
try {
id = Integer.parseInt(request.getParameter("id"));
} catch (NumberFormatException e) {
id = 0;
}
后,变量id的值为0(),如果数据库中没有id为0或其它对应的值,则
CD CD=dao.findCD(id);
后得到的CD变量指向的是null,也就是根本就不是一个CD对象。
当CD为null时,<%=CD.getCDID()%>自然会出现NullPointerException。
可能原因:
id参数没有获得正确的值,导致dao.findCD(id); 返回null。
在使用CD.getCDID时,应先判断CD是否为空,如:
<%
int id;
try {
id = Integer.parseInt(request.getParameter("id"));
} catch (NumberFormatException e) {
id = 0;
}
CDDAO dao=new CDDAO();
CD CD=dao.findCD(id);
if(CD == null){
//out.println("no info!");
}else{
// 自己看着办吧……
}
%>
分享到:
相关推荐
严重: Servlet.service() for servlet jsp threw exception java.lang.UnsupportedClassVersionError: com/util/PostUtil at org.apache.jsp.shouye.index_jsp._jspService(index_jsp.java:84) at org.apache....
2020-04-27 22:15:44.892 ERROR 13764 --- [nio-8081-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request ...
javax.servlet.ServletException: Servlet execution threw an exception root cause java.lang.Error: Unresolved compilation problem: The method setAttribute(String, Object) in the type ServletRequest ...
SpringMVC4.3.6配置json所需要的jar包,不是使用最新最高的版本可以的,我尝试了,有错误:严重: Servlet.service() for servlet [springMVC] in context with path [/30-returnVoid-ajax] threw exception [Handler...
严重: Servlet.service() for servlet dispatcherServlet threw exception java.lang.ClassNotFoundException: antlr.ANTLRException 当报antlr.ANTLRException错误时,只要添加一个这个jar就行了
严重: Servlet /LogMess threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet 这个问题应该是spring包所带来的问题,最后还是从新下了一个spring2.5的...
在做 jsp 上传图片时,把 java 代码直接改成 jsp,上传时产生 如下异常: 2012-12-31 8:59:21 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet jsp threw exception java...
因特网的路由选择协议
2011-1-8 20:34:20 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet default threw exception java.lang.IllegalStateException at org.apache.catalina.connector....
SpringBoot整合Listener的两种方式: ...1.创建一个类实现 ServletContextListener (具体实现哪个Listener根据情况来判断) 2.在类上加入注解 @WebListener 3.重写 contextInitialized() 与 contextDestroyed() ...
struts标签使用常见错误原因很多,这里积累了我遇见的几种错误及相应的解决方法。 同志们多注意积累——能让我们直接找到问题的原因所在,直接修改,提高开发效率,提升自我价值!