Servlet sendRedirect无法正常工作

时间:2018-03-25 15:09:19

标签: jsp redirect servlets

尝试执行从Servlet A的doPost到Servlet B的重定向。 我执行了以下代码:

response.sendRedirect("http://localhost:8080/App/BServlet");
return;

我可以看到导航器有302个HTTP代码执行GET请求到正确的位置,但是Servlet B的doGet方法没有被执行。

尝试使用301 Http方式,使用此代码:

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location","http://localhost:8080/App/BServlet");

在这种情况下,执行BServlet doGet方法但是,转发到Servlet B的doGet方法中包含的jsp页面并不转发到jsp页面,导航器停留在同一页面

有任何线索吗? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

As mentioned it Jonathan, and may some others check the answer, i was starting by a POST request, due to this, all the following requests will be post ones also even if a redirect start a new request.

相关问题