I want to call PhaseListener from doPost method of a Servlet. How can I do that?
I dont want to do like this
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/html/index.jsf");
dispatcher.forward(request, response);
Because in my PhaseListener am checking the viewId. And going by above method, the view id always remains to be index.xtml. So, am not able to check my conditions.
You are using a forward which does not start a new request, so you will keep the original request URI. You need to do a redirect which does start a new request and will give you the new request URI. So need to use:
Note that
response.sendRedirect()will set the status to 302. If you need a 301 status, you need to use: