从Servlet的doPost方法重定向到PhaseListener

时间:2012-08-28 15:20:20

标签: jsf servlets httpresponse

我想从PhaseListener的doPost方法中调用Servlet。我怎么能这样做?

我不想这样做

RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/html/index.jsf"); dispatcher.forward(request, response);

因为我PhaseListener正在检查viewId。按照上述方法,视图ID始终为index.xtml。所以,我无法检查我的情况。

1 个答案:

答案 0 :(得分:0)

您正在使用无法启动新请求的转发,因此您将保留原始请求URI。您需要执行重定向,该重定向会启动新请求并为您提供新请求URI。所以需要使用:

response.sendRedirect("/jsp/html/index.jsf");

请注意,response.sendRedirect()会将status设置为302.如果您需要301状态,则需要使用:

response.setStatus(301);
response.setHeader("Location", "/jsp/html/index.jsf");