使用 PrettyFaces 获取原始请求 URI
我在 JSF 应用程序中使用 PrettyFaces。该网站需要身份验证才能访问某些页面,因此我使用侦听器(预渲染视图)来检查用户是否已登录。因此,如果用户尝试访问 /foo (PrettyFaces 之前的 /foo.jsf),我会重定向到/登录。
但是,我想将它们重定向到其初始目的地,因此我想附加一个请求参数“next”,以便将用户重定向到 /login?next=/foo 。不幸的是,我无法从请求对象中获取原始的 requestURI,以下代码中的 uri 字符串是 /appname/foo.jsf 而不是 /appname/foo
ctx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) ctx.getRequest();
String uri = request.getRequestURI();
有没有办法检索原始 URI 路径?
I am using PrettyFaces in my JSF application. The site requires authentication to access some pages, so I'm using a listener (prerender view) that checks whether the user is logged in. So, if the user tries to access /foo (/foo.jsf before PrettyFaces), I redirect to /login.
However, I want to redirect them to their initial destination, so I want to attach a request parameter "next" so that I redirect the user to /login?next=/foo instead. Unfortunately, I can't get the original requestURI from the request object, the uri string in the following code is /appname/foo.jsf instead of /appname/foo
ctx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) ctx.getRequest();
String uri = request.getRequestURI();
Is there a way to retrieve the original URI path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PrettyFaces 在幕后使用
RequestDispatcher#forward()
将漂亮的 URL 转发到真实的 URL。使用此技术,原始请求 URI 可用作带有键RequestDispatcher#FORWARD_REQUEST_URI
。所以,这应该做:
PrettyFaces uses under the covers
RequestDispatcher#forward()
to forward a pretty URL to the real URL. Using this technique, the original request URI is available as request attribute with the keyRequestDispatcher#FORWARD_REQUEST_URI
.So, this should do:
使用此代码获取原始请求 URL:
Use this code to get the original request URL: