0

I am doing login application. I am encrypting the username and password parameters in login jsp and then I am sending it to servlet. In servlet I decrypt the username and password and dispatch to LoginAction page.Code as below

if(counter < loginLimit)
{

try{
    String sessionid = request.getSession(false).getId();
    response.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid + "; HttpOnly");
 }
 catch(Throwable t)
{
    GenericExceptionLog.log("DPLoginActionServlet :::: getting error::"+loginId+"  @ "+new java.sql.Timestamp(new java.util.Date().getTime()),"DPLoginActionServlet");
}

RequestDispatcher reqdisp=request.getRequestDispatcher(postLogin);
reqdisp.forward(request,response);
return;

}

but it givimg me java.lang.IllegalStateException: JBWEB000232: Cannot forward after response has been committed Occured

Ramesh
  • 15
  • 8

1 Answers1

0

Generally, the error you got say everything:

java.lang.IllegalStateException: Cannot forward after response has been committed

Before the call reqdisp.forward(request,response); you have written data to the response-buffer.
And if it is more than the buffer size, then it was committed to the browser.
So it's too late for forwarding.

What you can do:

  • look at you code before the forward() call and
  • find where the response was written
    • move your if-block with the forward() up there OR
    • add additional condition block around the response writing
code_angel
  • 1,537
  • 1
  • 11
  • 21