An extract from Developing Java Servlets
“The sendRedirect(String) should be called before the response is committed otherwise an IllegalStateException will be thrown…”
I am using Tomcat 4.1.12.
Following is the code snippet :
public void doGet(HttpServletRequest req,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
pw.println("Sun ONE");
response.flushBuffer();
response.sendRedirect("http://localhost:8080/servlet/DefaultImageServlet");
pw.close();
}
-------------
Output (In the Browser window) :
Sun ONE
-------------
Now in this case, neither I get an exception not I am redirected to DefaultImageServlet.
“The sendRedirect(String) should be called before the response is committed otherwise an IllegalStateException will be thrown…”
I am using Tomcat 4.1.12.
Following is the code snippet :
public void doGet(HttpServletRequest req,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
pw.println("Sun ONE");
response.flushBuffer();
response.sendRedirect("http://localhost:8080/servlet/DefaultImageServlet");
pw.close();
}
-------------
Output (In the Browser window) :
Sun ONE
-------------
Now in this case, neither I get an exception not I am redirected to DefaultImageServlet.