java servlet:response.sendRedirect() not giving illegal state exception if called after commit of re
Posted
by sahil garg
on Stack Overflow
See other posts from Stack Overflow
or by sahil garg
Published on 2009-06-21T08:35:22Z
Indexed on
2010/04/26
5:43 UTC
Read the original article
Hit count: 279
after commit of response as here redirect statement should give exception but it is not doing so if this redirect statemnet is in if block.but it does give exception in case it is out of if block.i have shown same statement(with marked stars ) at two places below.can u please tell me reason for it.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
synchronized (noOfRequests)
{
noOfRequests++;
}
PrintWriter pw=null;
response.setContentType("text/html");
response.setHeader("foo","bar");
//response is commited because of above statement
pw=response.getWriter();
pw.print("hello : "+noOfRequests);
//if i remove below statement this same statement is present in if block.so statement in if block should also give exception as this one do, but its not doing so.why?
***response.sendRedirect("http://localhost:8625/ServletPrc/login% 20page.html");
if(true)
{
//same statement as above
***response.sendRedirect("http://localhost:8625/ServletPrc/login%20page.html");
}
else{
request.setAttribute("noOfReq", noOfRequests);
request.setAttribute("name", new Name().getName());
request.setAttribute("GmailId",this.getServletConfig().getInitParameter("GmailId") );
request.setAttribute("YahooId",this.getServletConfig().getInitParameter("YahooId") );
RequestDispatcher view1=request.getRequestDispatcher("HomePage.jsp");
view1.forward(request, response);
}
}
© Stack Overflow or respective owner