How can I do server-side redirects from the old Servlet to JSF 2.0?

I am currently doing client-side redirects to switch from an obsolete servlet (old part of the application) to a JSF page (new part of the application). I would prefer to do a server side redirect if possible so that I can post items in a request that a JSF page can get. (there is a set of data that needs to be "given" between the old servlet and the JSF page, and I prefer not to put them in the redirect URL on the client side (as URL parameters), but instead do it on the server side).

If there is a way to do server-side redirects between the servlet (and not the Faces servlet) and the JSF page, can you show me how?

+3
source share
1 answer

Just call as RequestDispatcher#forward()usual. All servlets intercept and sent requests. You just need to make sure that the direct path matches the map FacesServlet. Assuming you matched it on *.xhtml, this should do:

request.getRequestDispatcher("/page.xhtml").forward(request, response);

If necessary, the page can be placed in a folder /WEB-INFif you want end users to not be able to open it directly without first calling the servlet.

request.getRequestDispatcher("/WEB-INF/page.xhtml").forward(request, response);
+2
source

All Articles