3 回答
TA贡献2037条经验 获得超6个赞
forward(), sendRedirect()sendError()
protected void doPost() {
if (someCondition) {
sendRedirect();
}
forward(); // This is STILL invoked when someCondition is true!}System#exit()someConditiontrueforward()sendRedirect()sendError()
java.lang.IllegalStateException:不能在提交响应后转发
ifforward()sendRedirect()sendError()
在提交响应后无法调用sendReDirect()
return;
protected void doPost() {
if (someCondition) {
sendRedirect();
return;
}
forward();}protected void doPost() {
if (someCondition) {
sendRedirect();
} else {
forward();
}}forward(), sendRedirect()sendError()
sendError()setStatus()
forward()
protected void doPost() {
out.write("some string");
// ...
forward(); // Fail!}forward()
java.lang.IllegalStateException:不能在提交响应后转发
request.setAttribute("data", "some string")${data}
另见:
不相干
TA贡献1828条经验 获得超3个赞
if(!response.isCommitted())// Place another redirection
TA贡献1853条经验 获得超18个赞
编辑
getServletConfig().getServletContext()
.getRequestDispatcher("/GroupCopiedUpdt.jsp")
.forward(request, response);将数据输出到输出流,或 事先做了另一次重定向。
添加回答
举报
