解决Cannot forward after response has been committed
Posted rogear
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决Cannot forward after response has been committed相关的知识,希望对你有一定的参考价值。
在是用request.getRequestDispatcher("目标地址URL").forward(request, response);时报错Cannot forward after response has been committed
字面意识是response已经提交过了不能再次提交,多次试了以后发现我的代码中有用了几次request.getRequestDispatcher("目标地址URL").forward(request, response);语句,执行到第一次的时候不会出错,后面会报错。另外应该注意该语句在使用的时候不是直接跳转页面,还会执行后面的代码。
解决方法方有两种:
1、在每个request.getRequestDispatcher("目标地址URL").forward(request, response);语句后面加一个return;
2、用一个对象装RequstDispatcher,在代码的最后使用forward方法。
以上是关于解决Cannot forward after response has been committed的主要内容,如果未能解决你的问题,请参考以下文章
java.lang.IllegalStateException: Cannot forward after response has been committed
Cannot forward after response has been committed 问题
Cannot create a session after the response has been committed解决方案
lsnrctl: .... cannot restore segment prot after reloc: Permission denied
Cannot create a session after the response has been committed的处理
Cannot call sendRedirect() after the response has been committ