使用 PrettyFaces 从 servlet 重定向/转发
我正在使用 PrettyFaces 3.3.0 我想从 servlet 进行自定义重定向和转发,
我在他们的文档中找到了以下代码:
public class CustomRedirector
{
public void redirect(HttpServletRequest request, HttpServletResponse response,
String mappingId, Map<String, String[]>params)
{
PrettyContext context = PrettyContext.getCurrentInstance(request);
PrettyURLBuilder builder = new PrettyURLBuilder();
URLMapping mapping = context.getConfig().getMappingById(mappingId);
String targetURL = builder.build(mapping, params);
targetURL = response.encodeRedirectURL(targetURL);
response.sendRedirect(targetURL);
}
}
我想知道如何从 servlet 调用重定向方法,mappingId(requestURI?)是什么以及什么是Map
的值,我需要一个从 servlet 调用上述方法的小例子吗?
以及如何使用漂亮面孔从 servlet 进行转发,请指教。
i am using PrettyFaces 3.3.0
and i want to make custom redirect and forward from a servlet
i found the following code on their documentation:
public class CustomRedirector
{
public void redirect(HttpServletRequest request, HttpServletResponse response,
String mappingId, Map<String, String[]>params)
{
PrettyContext context = PrettyContext.getCurrentInstance(request);
PrettyURLBuilder builder = new PrettyURLBuilder();
URLMapping mapping = context.getConfig().getMappingById(mappingId);
String targetURL = builder.build(mapping, params);
targetURL = response.encodeRedirectURL(targetURL);
response.sendRedirect(targetURL);
}
}
and i was wondering how to call the redirect method from the servlet, what will be the mappingId (the requestURI ?) and what will be the value of Map<String, String[]>params
, i need a small example please of calling above method from a servlet?
and how to do forwarding from servlet with prettyfaces too, please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“String mappingId”是 PrettyFaces 配置中 url 映射的 ID。每个 url 映射都应该有一个 ID(在 XML 或注释配置中)。Map
params 是名称-值对中的参数列表,用于根据指定的 URL 映射模式生成出站链接 。身份证号。
例如:
所以你会像这样调用你的方法:
你将被重定向到:
The "String mappingId" is the ID of the url-mapping in your PrettyFaces configuration. Each url-mapping should have an ID (either in the XML, or the Annotations configuration.)
The Map params is a list of parameters in name-value pairs that is used to generate the outbound link based on the URL-mapping pattern specified by the id.
For example:
So you would call your method like so:
And you will be redirected to: