jjava.lang.IllegalStateException: Cannot forward after response has been committed
at 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)

导致异常的代码:

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try { ........一个大字(略)
/**
* 6. 成功之后,将成功信息保存在request中
*/
request.setAttribute("msg", "添加成功");
request.getRequestDispatcher(
"/adminjsps/admin/dailyfix/meetting/addcategories.jsp")
.forward(request, response);
} catch (Exception e) {
if (e instanceof FileSizeLimitExceededException) {
request.setAttribute("msg", "上传文件的大小超出了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", "系统繁忙,请稍后再试...");
request.getRequestDispatcher(
"/adminjsps/admin/dailyfix/meetting/addcategories.jsp")
.forward(request, response);
}
}

  异常原因:  

  这个异常的意思是已有提交了,不能够再次转向。这个异常是由于多次提交或者页面中存在多个请求转发造成的,就是说在后台程序在return之前就执行了跳转或者执行了转发操作。

  异常解决办法:

  在转发语句之后,添加return语句,return ;

  如下代码解决问题:

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
一个大字(略)
/**
* 6. 成功之后,将成功信息保存在request中
*/
request.setAttribute("msg", "添加成功");
request.getRequestDispatcher(
"/adminjsps/admin/dailyfix/meetting/addcategories.jsp")
.forward(request, response);
} catch (Exception e) {
if (e instanceof FileSizeLimitExceededException) {
request.setAttribute("msg", "上传文件的大小超出了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", "系统繁忙,请稍后再试...");
request.getRequestDispatcher(
"/adminjsps/admin/dailyfix/meetting/addcategories.jsp")
.forward(request, response);
}
}

  

java.lang.IllegalStateException: Cannot forward after response has been committed的更多相关文章

  1. java.lang.IllegalStateException: Cannot forward after response has been committed的一个情况解决方法

    java.lang.IllegalStateException: Cannot forward after response has been committed xxx.xxx.doPost(upd ...

  2. nested exception is java.lang.IllegalStateException: Cannot forward after response has been committed

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...

  3. java.lang.IllegalStateException: Cannot forward after response has been committe

    参考:https://blog.csdn.net/lewky_liu/article/details/79845655 加上 return 搞定

  4. java.lang.IllegalStateException: getOutputStream() has already been called for this response

    ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...

  5. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response

    1. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this ...

  6. java.lang.IllegalStateException: getWriter() has already been called for this response问题解决

    java.lang.IllegalStateException: getWriter() has already been called for this response问题解决 java.lang ...

  7. 报错:java.lang.IllegalStateException: Cannot call sendError() after the response has been committed(待解答)

    严重: Servlet.service() for servlet [default] in context with path [/20161101-struts2-1] threw excepti ...

  8. java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

    http://blog.csdn.net/chenghui0317/article/details/9531171 —————————————————————————————————————————— ...

  9. 严重: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response

    严重: Servlet.service() for servlet jsp threw exception    java.lang.IllegalStateException: getOutputS ...

随机推荐

  1. jquery 使用a标签导航栏跳转页面,动态添加高亮

    众所周知,使用a标签跳转之后,会刷新一次,继而这个添加的样式就会消失.那么怎么解决这一问题呢? <script> $(function () { $('.bar a').each(func ...

  2. vue实现搜索功能

    vue实现搜索功能 template 部分 <!-- 搜索页面 --> <template> <div> <div class="goback&qu ...

  3. MYSQL中IN与EXISTS的区别

    在MYSQL的连表查询中,最好是遵循‘小表驱动大表的原则’ 一.IN与EXISTS的区别1.IN查询分析SELECT   *  FROM A WHERE id IN (SELECT id FROM B ...

  4. 破坏双亲委托机制的一些情况---Tomcat和JDBC,破坏后的安全问题

    采用双亲委托机制的原因 类加载器就是将字节码搬进jvm方法区的组件.我们知道,JVM识别加载进来的类是通过类加载器+类全名完成的,也就是说同一个类由不同类加载器加载进去的话就会被视为不同的类.jdk提 ...

  5. struts2+jsp 遍历 <s:iterator><s:property>

    直接把list用request传到jsp页面 <s:iterator var="u" value="#request.users"> <tr& ...

  6. Js中window.location.href和window.location.replace的区别

    href相当于打开一个新页面,replace相当于替换当前页面:这里打开页面都是针对历史记录来说,在页面上看完全相同,只是浏览器的history表现不同如果在1.html中点击链接到2.html,然后 ...

  7. web框架之初识Django

    目录 一.web框架 1.1什么是web框架 1.2自制的简易web框架 1.3三大主流web框架简介 Django Flask Tornado 1.4动态网页与静态网页 二.初识Django框架 2 ...

  8. dubbo、web应用 项目结构以及发布目录结构

    一.dubbo服务项目结构及发布结构 dubbo 服务项目结构 xxxxx-api 接口类和一些DTO 用于供其他项目依赖 需要提供dubbo服务的接口命名 以Facade结尾 (xxxxxFacad ...

  9. [POJ 1911] 棋盘

    问题描述 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘.(每次切割都只能沿着 ...

  10. hdu 4641K-string SAM的O(n^2)算法 以及 SAM+并查集优化

    转载:http://www.cnblogs.com/hxer/p/5675149.html 题意:有一个长度为n(n < 5e4)的字符串,Q(Q<=2e5)次操作:操作分为:在末尾插入一 ...