简体   繁体   English

java.lang.IllegalStateException:PWC1227:提交响应后无法转发……为什么要发送?

[英]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()方法中。

See also: 也可以看看:

使用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.

相关问题 java.lang.IllegalStateException:添加`return`后提交响应后无法转发 - java.lang.IllegalStateException: Cannot forward after response has been committed after add `return` java.lang.IllegalStateException:在servletfilter中提交响应后无法转发 - java.lang.IllegalStateException: Cannot forward after response has been committed in servletfilter java.lang.IllegalStateException:在提交响应后无法转发 - java.lang.IllegalStateException: Cannot forward after response has been committed java.lang.IllegalStateException:在404上提交响应后无法转发 - java.lang.IllegalStateException: Cannot forward after response has been committed on 404 随机java.lang.IllegalStateException:提交响应后无法转发 - Random java.lang.IllegalStateException: Cannot forward after response has been committed java.lang.IllegalStateException:提交响应后无法转发,位于com.java.QTD.QuestionOfTheDay.doGet() - java.lang.IllegalStateException: Cannot forward after response has been committed, at at com.java.QTD.QuestionOfTheDay.doGet() Spring boot:java.lang.IllegalStateException:响应提交后无法调用sendError() - Spring boot : java.lang.IllegalStateException: Cannot call sendError() after the response has been committed JSF 2.2 java.lang.IllegalStateException:提交响应后无法创建会话 - JSF 2.2 java.lang.IllegalStateException: Cannot create a session after the response has been committed Hibernate和Jackson(java.lang.IllegalStateException:提交响应后无法调用sendError()) - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) java.lang.IllegalStateException:在提交响应后无法调用sendRedirect() - java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM