如何从旧版Servlet到JSF 2.0进行服务器端重定向? [英] How can I do a server-side redirect from legacy Servlet to JSF 2.0?

查看:135
本文介绍了如何从旧版Servlet到JSF 2.0进行服务器端重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在执行客户端重定向,以从旧版servlet(应用程序的旧部分)到JSF页面(应用程序的新部分).如果可能的话,我希望进行服务器端重定向,以便将项目放置在请求中,以便JSF页面可以提取. (在旧版Servlet和JSF页面之间需要传递"一组数据,我不希望将它们放在客户端重定向URL(作为URL参数)中,而是在服务器上执行此操作,侧面).

I am currently doing a client-side redirect to get from a legacy servlet (old part of an application) to a JSF page (new part of an application). I would prefer to do a server-side redirect if possible, so that I may place items in the request that the JSF page can pick up. (there is a set of data that needs to be "handed off" between the legacy servlet and the JSF page and I prefer not to put these in a client-side redirect URL (as URL parameters) but instead do this on the server-side).

如果有一种方法可以在servlet(不是Faces servlet)和JSF页面之间进行服务器端重定向,请您告诉我如何做?

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

推荐答案

只需调用

Just call RequestDispatcher#forward() the usual way. All servlets intercept on forwarded requests as well. You just need to make sure that the forward path matches the FacesServlet mapping. Assuming that you've mapped it on *.xhtml, this should do:

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

如果要防止最终用户无需先调用servlet就可以直接打开页面,则可以将页面放置在/WEB-INF文件夹中.

The page can if necessary be placed in /WEB-INF folder if you want to prevent the endusers from being able to open it directly without invoking the servlet first.

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

这篇关于如何从旧版Servlet到JSF 2.0进行服务器端重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆