Jsf 使用OcpSoft rewrite Join.path规则重写URL

Jsf 使用OcpSoft rewrite Join.path规则重写URL,jsf,url-rewriting,prettyfaces,ocpsoft-rewrite,Jsf,Url Rewriting,Prettyfaces,Ocpsoft Rewrite,我正在使用Ocpsoft Rewrite,在JSF项目中执行URL重写。我有一个重定向规则,它可以正常工作: .addRule() .when(Direction.isInbound().and(Path.matches("/venue/{id}"))) .perform(Redirect.temporary(context.getContextPath() + "/protected/index.xhtml?venueID={i

我正在使用Ocpsoft Rewrite,在JSF项目中执行URL重写。我有一个重定向规则,它可以正常工作:

.addRule()
        .when(Direction.isInbound().and(Path.matches("/venue/{id}")))
        .perform(Redirect.temporary(context.getContextPath() + 
                "/protected/index.xhtml?venueID={id}"));
但是,由于重定向,这会更改导航栏中的URL。我原以为可以使用联接规则,但它并没有像我预期的那样工作:

.addRule(Join.path("/venue/{venueID}").to("/protected/index.xhtml"))
        .perform(Log.message(Level.INFO, "Rewrite is active!"));
我以为这个规则会从例如
foo/venue/123
重定向到
foo/protected/index.xhtml?venueID=123
,但我没有将
?venueID=…
参数附加到URL


有人知道正确的规则应该是什么样子吗?

您的规则看起来是正确的。但是联接不会导致重定向。相反,它在内部转发请求。这意味着URL没有更改。因此,您不会在URL中“看到”参数
venueID
。但您可以使用标准Servlet API读取参数:

String id = HttpServletRequest.getParameter("venueID");

如果确实需要,您可以执行
转发

.addRule()
.when(Direction.isInbound().and(Path.matches("/venue/{id}")))
.perform(Forward.to("/protected/index.xhtml?venueID={id}"));

但这不会像Join那样处理出站HTML链接更正

我在GWT应用程序中也遇到了同样的问题,但我无法获取GWT端的参数:Window.Location.getParameter(“param”);好的,但是如果有其他参数,这些参数是否会被转发?不,它只转发您在模式中指定的参数。但是,正如Christian前面提到的。所有参数,包括来自原始URL的原始参数,都可以通过标准ServletAPI获得:String id=HttpServletRequest.getParameter(“venueID”);如何在GWT端达到这些参数?Window.Location.getParameter(“参数”)不起作用。