关于java.lang.IllegalStateException: Cannot forward after response has been committed异常问题?
先看下面这几段代码:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String str = "nihaoma";
OutputStream out = response.getOutputStream();
out.write(str.getBytes());
//关闭字节输出流资源
out.close();
//转发
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
为什么在调用forward方法之前,在Servlet程序中写入的部分内容已经被真正地传送到了客户端的情况下,forward方法抛出IllegalStateException异常? |