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