Java.lang.IllegalStateException:Cannot create a session after the response has been committed

Source: Internet
Author: User
Tags session id

Sometimes when the session is being manipulated, the system throws the following exception

Java.lang.IllegalStateException:Cannot create a session after the response has been committed

This type of problem occurs because we create a session after the response output response.

(because the server already sent the data to the client, that is, the session ID could not be sent)

Solution:

1. Create a statement to access the session "Request.getsession ()" Before the response output data is good.

For example, change to the following wording OK:

Servletoutputstream out = Response.getoutputstream ();
It's best to be next to Response.getoutputstream ()
HttpSession seesion = Request.getsession ();
Seesion.setattribute ("xxx", Rand);
Output data
Out.print ("Out.close ();

2. If you use the STRUTS2, you can add a default interceptor to the Struts.xml:

<interceptor-ref name= "CreateSession"/>
<interceptor-ref name= "Defaultstack"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.