各位CSDN的坛友,小弟急向大家请教一个问题。
我用如下一个方法向session中存储字符串,然后定向发送到一个JSP页面:
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException { req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
} 其中"Str"是说明性文字, errorpage.jsp 是调用session里数据的另一个页面。 感觉没有什么错误,因为在其它的地方也是如此用的就可以正常运行。 而现在,总是报错如下:
java.lang.IllegalStateException: Cannot forward after response has been committed
com.course.StudentLoginSvlt.doError(StudentLoginSvlt.java:116)
com.course.StudentLoginSvlt.doEnrol(StudentLoginSvlt.java:78)
com.course.StudentLoginSvlt.doGet(StudentLoginSvlt.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)我找了很久原因,就是无劳而返,望各位高手指教。 拜谢。
我用如下一个方法向session中存储字符串,然后定向发送到一个JSP页面:
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException { req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
} 其中"Str"是说明性文字, errorpage.jsp 是调用session里数据的另一个页面。 感觉没有什么错误,因为在其它的地方也是如此用的就可以正常运行。 而现在,总是报错如下:
java.lang.IllegalStateException: Cannot forward after response has been committed
com.course.StudentLoginSvlt.doError(StudentLoginSvlt.java:116)
com.course.StudentLoginSvlt.doEnrol(StudentLoginSvlt.java:78)
com.course.StudentLoginSvlt.doGet(StudentLoginSvlt.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)我找了很久原因,就是无劳而返,望各位高手指教。 拜谢。
如果你要转发到这上面errorpage.jsp,那么下面这句应该就不用了,你直接在后面写个return null就可以解决了!