java.lang.IllegalStateException:PWC1227:提交响应后无法转发......为什么会出现?
要将一些行数据添加到表中,提交按钮后,我必须在相关表的下一页中显示详细信息(数据)。当我使用 RequestDispather
类时,我收到 java.lang.IllegalStateException:
........ 它也在使用 response.sendRedirect 时出现("View.jsp");
.....我正在发送我在页面中使用的代码。
if(msg.equals("Values Added")){
RequestDispatcher rd = request.getRequestDispatcher("View.jsp");
rd.forward(request, response);
}
(或者)
if(msg.equals("Values Added")){
response.sendRedirect("View.jsp");
}
to add some row data into a table, affter submmiting the button i have to show the details(data) in the next page of that regarding table. when i am using RequestDispather
class i am getting the java.lang.IllegalStateException:
........ it was also comming while using response.sendRedirect("View.jsp");
..... i am sending the code what i used in my page.
if(msg.equals("Values Added")){
RequestDispatcher rd = request.getRequestDispatcher("View.jsp");
rd.forward(request, response);
}
(OR)
if(msg.equals("Values Added")){
response.sendRedirect("View.jsp");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JSP 是响应的一部分。您无法像在 JSP 内部那样更改响应。那时就太晚了。这段代码应该放在servlet类中。
更改您的表单以提交到 servlet:
创建一个映射到
/servleturl/*
的url-pattern
的 servlet 类,并将您拥有的所有 Java 代码移至此处在 JSP 中插入doPost()
方法。另请参阅:
JSP is part of the response. You cannot change the response like that from inside a JSP. It's too late then. This piece of code should have been placed in a servlet class.
Change your form to submit to a servlet instead:
Create a servlet class which is mapped on an
url-pattern
of/servleturl/*
and move all the Java code you have there in JSP into thedoPost()
method.See also:
以下内容本身并不正确:
“您无法像从 JSP 内部那样更改响应。那么就太晚了。”
只需将回发检查和重定向放在 jsp 中的 html 标记之前...然后一切都会好起来的。
所以:
...
The following is not true per se:
"You cannot change the response like that from inside a JSP. It's too late then."
Just place your postback check and redirect before the html tag in your jsp...then everything will be fine.
So:
<html > ... </html>
使用 else if 代替 if
use else if in place of if