Unable to create a session after receiving a response
The exception message is pretty clear. There are funds from an illegal state. You can no longer set / change response headers when the answer is already made. The response is executed when headers are already sent to the client side. This is a point with no return .
The response will be executed whenever the output stream has been flushed (in) directly. This can happen if you write more than 2K of the answer (depending on the server configuration), or did flush() manually or made a call to sendRedirect() .
Whenever a session is to be created, the server needs to set a cookie in the response header so that it can identify a specific client and associate it with an HttpSession instance in server memory. But this is not possible if the answer has already been made, so this is an exception.
Back to the root cause of this problem:
Servlet.service () for Captcha servlet throws an exception
This is caused by this servlet problem with servlet-name of Captcha . You need to check / debug the entire request and response chain to see which servlets / filters are all called, and which one could pass the response before the Captcha servlet could create the session. I can not help you in more detail, because this information is not in your topic.
At least in the code example below, I see that you call response.getWriter() unnecessarily . I'm not sure what the real world code looks like, you may have split some lines, but most likely you are actually writing to it, and this may be the main cause of the problem. If you write too much or make a flash on it, then the reponing will be completed. Do not write the response inside the servlet, which should be the controller. There you usually use JSP. Or if this is for debugging purposes, use stdout ( System.out.println() ) or Logger .
Balusc
source share