java.lang.IllegalStateException: Cannot forward after response has been committed
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的更多相关文章
- java.lang.IllegalStateException: Cannot forward after response has been committed的一个情况解决方法
java.lang.IllegalStateException: Cannot forward after response has been committed xxx.xxx.doPost(upd ...
- nested exception is java.lang.IllegalStateException: Cannot forward after response has been committed
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...
- java.lang.IllegalStateException: Cannot forward after response has been committe
参考:https://blog.csdn.net/lewky_liu/article/details/79845655 加上 return 搞定
- java.lang.IllegalStateException: getOutputStream() has already been called for this response
ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang ...
- 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this response
1. 用java实现文件下载,提示java.lang.IllegalStateException: getOutputStream() has already been called for this ...
- java.lang.IllegalStateException: getWriter() has already been called for this response问题解决
java.lang.IllegalStateException: getWriter() has already been called for this response问题解决 java.lang ...
- 报错: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 ...
- java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
http://blog.csdn.net/chenghui0317/article/details/9531171 —————————————————————————————————————————— ...
- 严重: 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 ...
随机推荐
- P5444 [APIO2019]奇怪装置
传送门 考虑求出最小的循环节 $G$ 使得 $t,t+G$ 得到的数对是一样的 由 $y \equiv t \mod B$ ,得到 $G$ 一定是 $B$ 的倍数,设 $zB=G$,则 $t,t+zB ...
- [SheetJS] js-xlsx模块学习指南
简介 SheetJS是前端操作Excel以及类似的二维表的最佳选择之一,而js-xlsx是它的社区版本. js-xlsx将注意力集中到了数据转换和导出上,所以它支持相当多种类的数据解析和导出.不仅仅局 ...
- Ubuntu 安装 ansible
sudo apt update sudo apt-get install software-properties-common sudo apt-add-repository --yes ppa:an ...
- javaScript基础--概念以及使用
1.什么javascript? 为什么要学习? 处理网站动态特效 为后期课程打基础 什么是javascript? 是一个客户端的具有安全性的脚本语言. js和h5 的关系 : 都是向静态的元素动起来 ...
- CentOS7搭建Storm集群及基础操作
前提 安装Kafka前需要先安装zookeeper集群,集体安装方法请参照我的另一篇文档 Storm安装 下载 wget https://mirrors.tuna.tsinghua.edu.cn/ap ...
- web开发中SESSION的本质
有一点我们必须承认,大多数web应用程序都离不开session的使用.这篇文章将会结合php以及http协议来分析如何建立一个安全的会话管理机制.我们先简单的了解一些http的知识,从而理解该协议的无 ...
- Linux下C语言实现ATM取款机,消息队列版本
链接:https://pan.baidu.com/s/1oBavXBuZul7ZAEBL1eYfRA 提取码:ffhg Mybank ATM取款机实验,消息队列实现本实验用的是Centos71.在服务 ...
- 从1到n整数中1出现的次数(整数中1出现的次数)
题目 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了.AC ...
- hdu 4082 Hou Yi's secret(暴力枚举)
Hou Yi's secret Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Java final、static 关键字
问:谈谈 Java 中 final.finally.finalize 的区别? 答:这道题其实没有任何意义,无非就是考察开发者有没有区分这几个关键字的含义,仅仅关联是因为长得像而已. final ...