servlet转发时候出现空指针异常 10
Servlet.service()forservletjspthrewexceptionjava.lang.NullPointerExceptionatorg.apach...
Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.forquestion_jsp._jspService(forquestion_jsp.java:342)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.gh.zhaoping.servlet.ForQuestion.doGet(ForQuestion.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.wabacusdemo.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:64)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke
private String user_qestion = "/forquestion.jsp";
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
CommonServiceImpl.setQuestioninfo(request);
// System.out.println(request.getAttribute("lxrname"));
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher(user_qestion);
// System.out.println("--------------------");
dispatcher.forward(request, response);
}
这是我的servlset 现在出的问题是 假如我有 a,b,c三个页面 直接由b->servlet->c 能成功,但是由a 跳到 b 再走b->servlet->c 就会报这个异常 不理解怎么回事 展开
java.lang.NullPointerException
at org.apache.jsp.forquestion_jsp._jspService(forquestion_jsp.java:342)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.gh.zhaoping.servlet.ForQuestion.doGet(ForQuestion.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.wabacusdemo.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:64)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke
private String user_qestion = "/forquestion.jsp";
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
CommonServiceImpl.setQuestioninfo(request);
// System.out.println(request.getAttribute("lxrname"));
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher(user_qestion);
// System.out.println("--------------------");
dispatcher.forward(request, response);
}
这是我的servlset 现在出的问题是 假如我有 a,b,c三个页面 直接由b->servlet->c 能成功,但是由a 跳到 b 再走b->servlet->c 就会报这个异常 不理解怎么回事 展开
6个回答
展开全部
从a到b你传了哪些值,把他打印出来,再在servlet中把你所传进来的参数打印下,传出去的参数也打印下,就能知道那个对象空了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
设个断点,看一下那个变量没有数据,用degug模式运行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果猜的没错 你应该在页面取东西了 ,问题在于RequestDispatcher dispatcher = context.getRequestDispatcher(user_qestion);
你这行代码是Dispathcher 只对第二个页面有效 所以参数是传不到重定向页面的换成forward 试试
你这行代码是Dispathcher 只对第二个页面有效 所以参数是传不到重定向页面的换成forward 试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-12-13 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
servlet的空指针是由于jsp页面应用了null对象导致,里面的service方法抛出的异常。
遇到这种情况要及从错误里面捕捉异常抛出的原因,跟踪代码调试修复。
处理方式 1) 检查到对象为空时,设置对象值为空字符串或一个默认值;
处理方式 2) 检测到对象为空时,根本不执行某操作,直接跳转到其他处理中。
处理方式 3) 检查到对象为空时,提示用户操作有错误。
遇到这种情况要及从错误里面捕捉异常抛出的原因,跟踪代码调试修复。
处理方式 1) 检查到对象为空时,设置对象值为空字符串或一个默认值;
处理方式 2) 检测到对象为空时,根本不执行某操作,直接跳转到其他处理中。
处理方式 3) 检查到对象为空时,提示用户操作有错误。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你这样没有人可以回答的出,贴程序吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询