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 ...
随机推荐
- TCP/IP详解学习笔记(3)IP协议ARP协议和RARP协议
把这三个协议放到一起学习是因为这三个协议处于同一层,ARP协议用来找到目标主机的Ethernet网卡Mac地址,IP则承载要发送的消息.数据链路层可以从ARP得到数据的传送信息,而从IP得到要传输的数 ...
- k3 cloud中获取年月日
日期类型字段元素.Date.Year(获取年) 日期类型字段元素.Date.Month(获取月)日期类型字段元素.Date.Day(获取天)
- JavaScript ES6 Promise对象
说明 Node.js中,以异步(Async)回调著称,使用了异步,提高了程序的执行效率,但是,代码可读性较差的. 假如有几个异步操作,后一个操作需要前一个操作的执行完毕之后返回的数据才能执行下去,如果 ...
- vue.js 笔记
<!-- 多层for循环 --> <ul> <li v-for="(ite,key) in list2"> {{key}}-------{{it ...
- 关于windows服务器配置
#我是用的window service2008系统,在配置服务器时由于是用php进行搭建 #首先我安装好phpstudy,通过服务器ip访问,显示了个helloworld,我查看了phpstudy里的 ...
- thinkphp获取目录的方法
1.获取根目录 http://localhost/ 下面两种方法效果一样 $_SERVER['REQUEST_SCHEME']."://".$_SERVER['HTTP_HOST' ...
- AIX下的ha高可用集群cluster
安装ha软件 一.安装软件 最稳定的版本是5.4.0,优先安装稳定版本5.4 安装依赖于包base.data, cluster的man包安装失败原因是缺少base.data包 安装所有cluster. ...
- python tkinter画圆
x0=150 #圆心横坐标 y0=100 #圆心纵坐标 canvas.create_oval(x0-10,y0-10,x0+10,y0+10) #圆外矩形左上角与右下角坐标 canv ...
- hdu 6152 : Friend-Graph (2017 CCPC网络赛 1003)
题目链接 裸的结论题.百度 Ramsey定理.刚学过之后以为在哪也不会用到23333333333,没想到今天网络赛居然出了.顺利在题面更改前A掉~~~(我觉得要不是我开机慢+编译慢+中间暂时死机,我还 ...
- 禁止input输入框输入指定内容
链接: http://blog.csdn.net/xiaoya_syt/article/details/52746598