gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:56:15 37 4
gpt4 key购买 nike

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

.addRule()
.when(Direction.isInbound().and(Path.matches("/venue/{id}")))
.perform(Redirect.temporary(context.getContextPath() +
"/protected/index.xhtml?venueID={id}"));

但是,由于重定向,这会更改导航栏中的 URL。我以为我可以改用 Join 规则,但它并没有像我预期的那样工作:

.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,但我不知道获取附加到 URL 的 ?venueID=... 参数。

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

最佳答案

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

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

关于jsf - 使用 OcpSoft rewrite Join.path 规则重写 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23582991/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com