• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about sendRedirect

 
mohamed ewis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sendredirect : i know taht We cannot call this method if the response is committed�that is,if the response header has already been sent to the browser
but when i write it after commiting response no exception thrown ,why

PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>NewServlet at "
+ request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
response.sendRedirect("http://www.cnn.com");
 
Abi Ted
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the response buffer is just filled.... it is not committed....

or out.flush() not called yet...
 
mohamed ewis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Abinesh for your reply
manuly flush response and still no exception

PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>NewServlet at "
+ request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
out.flush(); // flush response
response.sendRedirect("http://www.cnn.com");
 
Abi Ted
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see a try{ in your program... what exception are you handling??

because some programmers handle it this way...
try{
}catch(Exception e){}

This is wrong...
Please post the catch also...
 
Amol Fuke
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this :


and it throws exception on console.

Thanks,
Amol
 
mohamed ewis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi amol ,thanks for reply
i tried the code as you wrote and no exceptions thrown ,
it out NewServlet at /JSPStudy in browser window
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic