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. 更新SVN时提示要清理,但清理失败,乱码得解决方案

    问题情况如图: 解决办法: 依托工具——sqlite3, 首先在项目根目录下找到.svn文件夹,将其中的wc.db复制到工具所在路径. 如果找不到.svn,需要把隐藏文件选项勾去. 路径如图: 此时, ...

  2. php使用Socket实现聊天室功能(书中的代码)

    这只是一种技术 <?php $host = "127.0.0.1"; // 指定监听的端口,注意该端口不能与现有应用的端口冲突 $port = '9505'; $null = ...

  3. Javascript | DOM\DOM树浅析

    DOM Document Object Model(文档对象模型) 定义了表示和修改文档所需的方法. DOM对象即为宿主对象,由浏览器厂商定义,用来操作html和xml功能的一类对象的集合.也有人称D ...

  4. 朴素贝叶斯算法——实现新闻分类(Sklearn实现)

    1.朴素贝叶斯实现新闻分类的步骤 (1)提供文本文件,即数据集下载 (2)准备数据 将数据集划分为训练集和测试集:使用jieba模块进行分词,词频统计,停用词过滤,文本特征提取,将文本数据向量化 停用 ...

  5. 初学Java 数组统计字母

    public class CountLetterInArray { public static void main(String[] args) { char[] chars = createArra ...

  6. 02scikit-learn模型训练

    模型训练 In [6]: import numpy as np import matplotlib.pyplot as plt from sklearn.linear_model import Lin ...

  7. 手工实现Array List和Linked List

    Array List样例: /** * 增加泛型 * 自动增加数组容量 * 增加set.get方法:增加数组边界的检查 * 增加remove方法 */package cn.study.lu.four; ...

  8. RAC搭建---自己做

    一.本地磁盘是指你本身加上去的磁盘,只能本机使用的.共享磁盘是指可以多台机器同时读取写入.你做RAC就要用到共享存储: 二.ORC分区一般1G*3  数据分区5G*3  ,FRA分区一般5G*3  这 ...

  9. git怎样删除未监视的文件untracked files ?

    git怎样删除未监视的文件untracked files 需要添加到.gitignore文件 # 删除 untracked files git clean -f # 连 untracked 的目录也一 ...

  10. 微信公众号号开发(Java)

    参考:http://www.cnblogs.com/fengzheng/p/5023678.html http://www.cnblogs.com/xdp-gacl/p/5151857.html 一: ...