我在JSP中有下面的代码。页面没有被重定向
try {
...
if (...)
response.sendRedirect("secondPage.jsp");
...
} catch (Exception e) {
response.sendRedirect("thirdPage.jsp");
}
页面没有按照代码重定向。 我在服务器中获得IllegalStateException
。
我在JSP中有下面的代码。页面没有被重定向
try {
...
if (...)
response.sendRedirect("secondPage.jsp");
...
} catch (Exception e) {
response.sendRedirect("thirdPage.jsp");
}
页面没有按照代码重定向。 我在服务器中获得IllegalStateException
。
正如我所知...... 转接呼叫后:
这里两件事情,以通知:
所以牢记这一点,你应该提供绝对URL(包括网页上下文或网站根目录文件夹)高达您的最终目的地资源,而不是相对网址。
你的代码应该工作。但是,我建议使用<JSP:FORWARD>
。
例子: -
<jsp:forward page="index.jsp" />
它更贴近您的purpose.Try,并希望它会帮助你。
确保你没有写任何东西到你的sendRedirect命令之前响应。
既然你得到了IllegalStateException它看起来像你的jsp已经写了一些内容到响应,然后尝试重定向。
在这种情况下更好的选择是在一个Servlet中编写你的逻辑。
[java.lang.IllegalStateException:在提交响应后无法转发]的可能重复(http://stackoverflow.com/questions/2123514/java-lang-illegalstateexception-cannot-forward-after-response-has-已提交) – Lion 2013-04-29 05:16:16
如果您有异常堆栈跟踪,那么请不要忘记下次发布完整的异常堆栈跟踪。 – Lion 2013-04-29 05:19:08