[英]java.lang.IllegalStateException: PWC1227: Cannot forward after response has been committed…why it was comming?
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");
当我使用RequestDispather
类时,我正在获取java.lang.IllegalStateException:
........在使用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");
}
JSP is part of the response. JSP是响应的一部分。 You cannot change the response like that from inside a JSP. 您无法从JSP内部更改响应。 It's too late then. 那时为时已晚。 This piece of code should have been placed in a servlet class. 这段代码应该放在servlet类中。
Change your form to submit to a servlet instead: 更改您的表单以提交给servlet:
<form action="servleturl" method="post">
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 the doPost()
method. 创建一个Servlet类,该类映射到/servleturl/*
的url-pattern
, /servleturl/*
JSP中存在的所有Java代码移到doPost()
方法中。
使用else代替if
The following is not true per se: 以下内容本身是不正确的:
"You cannot change the response like that from inside a JSP. It's too late then." “您不能从JSP内部更改响应。那时为时已晚。”
Just place your postback check and redirect before the html tag in your jsp...then everything will be fine. 只需将您的回发检查并重定向到jsp中的html标记之前即可。
So: 所以:
<% if(msg.equals("Values Added")){
response.sendRedirect("View.jsp");
} %>
<html > ... </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.