Servlet 获取IllegelStateException:
response提交之后,进行requestDispatcher.forwar(),会产生这样的问题;
但是必须是outputStream.flush()才可以,或者PrintWriter.flush();
package com.stono.servlet.synchronize; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class TestServletD extends HttpServlet { private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // ServletOutputStream os = resp.getOutputStream(); // os.print(0); // os.flush(); PrintWriter writer = resp.getWriter(); writer.println("this is from printwriter"); writer.flush(); RequestDispatcher dispatcher = req.getRequestDispatcher("a.do"); dispatcher.forward(req, resp); } }