Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Redirecting to other Web Resource  RSS feed

 
Jaggi Kunal
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Engin Okucu
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jaggi,
With Tomcat you won't get this exception, you must try it with other things than Tomcat.
I already read it in this forum once(somebody was at the same situation as you)...search in this forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!