Cannot call sendRedirect() after the response has been committed错误;

Cannot call sendRedirect() after the response has been committed
提示信息其实很清楚,如果response已经提交过了,就无法再发送sendRedirect了。

因为重定向,其实是HTTP-302,如果你之前已经写过数据,那么默认就是HTTP-200,浏览器都收到HTTP-Head信息了,就没机会做重定向了。


所以,在进行:
  resp.sendRedirect()
之前,必须先保证没有任何的输出,包括:
1、Cookie;
2、resp.getWriter()写文本信息;
3、已经发送过重定向。


重点检查下这些问题吧,如果你写了Filter,或者Servlet已经做过forward,也要注意看看

原文地址:https://www.cnblogs.com/shizhijie/p/8018875.html