Java.lang.IllegalStateException:Cannot forward after response have been committed

Source: Internet
Author: User

Jjava.lang.IllegalStateException:Cannot forward after response have been committedAt Org.apache.catalina.core.ApplicationDispatcher.doForward (applicationdispatcher.java:312) at Org.apache.catalina.core.ApplicationDispatcher.forward (applicationdispatcher.java:302) at Com.sxt.hotel.meeting.web.servlet.admin.AddCMeetServlet.doPost (addcmeetservlet.java:80) at Javax.servlet.http.HttpServlet.service (httpservlet.java:643) at Javax.servlet.http.HttpServlet.service ( httpservlet.java:723) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter ( applicationfilterchain.java:290) at Org.apache.catalina.core.ApplicationFilterChain.doFilter ( applicationfilterchain.java:206) at Org.apache.catalina.core.StandardWrapperValve.invoke ( standardwrappervalve.java:233) at Org.apache.catalina.core.StandardContextValve.invoke (Standardcontextvalve.java : 191) at Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:127) at Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:103) at Org.apache.catalina.core.StandardEngineValve.invoke (Standardenginevalve.java:109) at Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:293) at Org.apache.coyote.http11.Http11AprProcessor.process (http11aprprocessor.java:876) at Org.apache.coyote.http11.http11aprprotocol$http11connectionhandler.process (http11aprprotocol.java:612) at Org.apache.tomcat.util.net.aprendpoint$worker.run (aprendpoint.java:1777) at Java.lang.Thread.run (thread.java:722 )

Code that causes the exception:

public void DoPost (HttpServletRequest request, httpservletresponse response) Throws Servletexception, IOException {try {... A large print (slightly)/** * 6. After successful, save the Success information in Request */request.setattribute ("MSG", "add Success"); Request.getrequestdispatcher ("/adminjsps/admin/ Dailyfix/meetting/addcategories.jsp "). Forward (request, response);} catch (Exception e) {if (e instanceof filesizelimitexceededexception) {Request.setattribute ("msg", "the size of the uploaded file exceeds 50kb"); Request.getrequestdispatcher ("/adminjsps/admin/dailyfix/meetting/addcategories.jsp"). Forward (request, response) ;} if (e instanceof hotelexception) {Request.setattribute ("msg", E.getmessage ()); Request.getrequestdispatcher ("/ Adminjsps/admin/dailyfix/meetting/addcategories.jsp "). Forward (request, response);} Request.setattribute ("MSG", "System busy, please try again later ..."); Request.getrequestdispatcher ("/adminjsps/admin/dailyfix/meetting/            Addcategories.jsp "). Forward (request, response);} 

Exception Reason:

This exception means that it has been submitted and cannot be turned again. This exception is due to multiple commits or the presence of more than one request forwarding in the page, which means that the daemon performs a jump or a forward operation before the return.

Exception Workaround:

After forwarding the statement, add the return statement, return;

The following code solves the problem:

public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {try { A large print (slightly)/** * 6. After successful, save the Success information in Request */request.setattribute ("MSG", "add Success"); Request.getrequestdispatcher ("/adminjsps/admin/ Dailyfix/meetting/addcategories.jsp "). Forward (request, response);} catch (Exception e) {if (e instanceof filesizelimitexceededexception) {Request.setattribute ("msg", "the size of the uploaded file exceeds 50kb"); Request.getrequestdispatcher ("/adminjsps/admin/dailyfix/meetting/addcategories.jsp"). Forward (request, response) ;return;}if (e instanceof hotelexception) {Request.setattribute ("msg", E.getmessage ()); Request.getrequestdispatcher ("/ Adminjsps/admin/dailyfix/meetting/addcategories.jsp "). Forward (request, response);return;}request.setattribute ("MSG", "System busy, please try again later ..."); Request.getrequestdispatcher ("/adminjsps/admin/dailyfix/meetting/ Addcategories.jsp "). Forward (request, response);}

  

Java.lang.IllegalStateException:Cannot forward after response have been committed

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.