我有一個源代碼Servlet。異常在servlet jsp和servlet中的java.lang.NullPointerException
SinhVien sv= new SinhVien();
String url="../lienhepage.jsp";
HttpSession session = request.getSession(true);
//RequestDispatcher rD;
//HttpSession session;
if(request.getParameter("searchword")!= ""){
String result= "";
result= ZendCodeHTML.ZendCodeTag(sv.getDataTag(request.getParameter("searchword")));
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(result);
}
if(request.getParameter("NienKhoa") != ""){
List<String> result= getData(request.getParameter("NienKhoa"));
session.setAttribute("tieude", result.get(0));
session.setAttribute("danhsachsinhvien", result.get(1));
session.setAttribute("cacmongiangday", result.get(2));
session.setAttribute("noidunghuongdanmonhoc", result.get(3));
}
RequestDispatcher rD= request.getRequestDispatcher(url);
rD.forward(request, response);
當我點擊頁面中的鏈接的jsp有URL =」 ../ lienheservlet?NienKhoa = 2010- 2015" 年,那麼代碼的servlet運行正常。但當代碼運行功能rD.forward(request, response);
然後有這樣的例外:
java.lang.NullPointerException
javacore.controller.lienheservlet.doGet(lienheservlet.java:115)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
我不知道爲什麼?請幫幫我!
什麼的javadoc的'getRequestDispatcher'說創建一個包裝? –
@SotiriosDelimanolis當我調試運行函數RequestDispatcher rD = request.getRequestDispatcher(url);然後完成rD = null;我不知道爲什麼? –
getRequestDispatcher的javadoc說什麼? –