j_security_check url问题

发布于 2024-09-15 16:45:05 字数 1392 浏览 7 评论 0原文

希望你能帮我解决这个问题: 我正在使用 j_security_check 并遇到这个问题

我有一个配置文件页面必须限制为任何未登录的用户, 所以我在 web.xml 文件中添加了安全约束并且工作正常 如果我尝试通过地址栏访问,这会显示登录页面,

现在问题是:在我的索引页面示例中:

http://localhost/mySite/index.xhtml

有一个链接

这会将我重定向到个人资料页面,但 URL 仍然相同

http://localhost/mySite/index.xhtml

所以 j_security_check 不显示登录页面 据我所知, j_security_check 可以与 url 一起使用,而 jsf 则不能 如果在个人资料页面中点击 ex:myImages 的链接,那么现在的 url 会显示:

例如:http://localhost/mySite/user/Profile.xhtml

为什么会发生这种情况?有办法解决这个问题吗? 预先感谢

我一直在使用的替代方案是点赞

个人资料

这向我显示了登录页面,但如果我转到index.xhtml并按个人资料,则找不到页面,因为将我重定向到:

例如:http://localhost/mySite/user/user/Profile.xhtml

hope you can help me with this:
I'm working with j_security_check and have this problem

I have a profile page that must be restricted to any unloged user,
so i add a security constraint in the web.xml file and works fine
if i try to access by adress bar, this show me the login page perfectly ok

now the problem is that: In my index page example:

http://localhost/mySite/index.xhtml

have a link

<h:commandLink action="user/Profile" />

this redirect me to profile page ok but the URL still the same

http://localhost/mySite/index.xhtml

so j_security_check don't show the login page
as far as i've seen j_security_check works with url and jsf don't
and if in the profile page press a link to ex:myImages then now the url says:

ex: http://localhost/mySite/user/Profile.xhtml

Why is this happend? is there anyway to fix this ??
Thanks in advance

an alternative i've been using is put a like

<a href="user/Profile.xhtml" >Profile</a>

this show me the login page but if i go to the index.xhtml and press profile this don't find the page because redirects me to:

ex: http://localhost/mySite/user/user/Profile.xhtml

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

活泼老夫 2024-09-22 16:45:05
<h:commandLink action="user/Profile" />

h:commandLinkh:commandButton当前触发 HTTP POST 请求(通过 h:form) > 页面,该页面又转发到给定的资源。

您不想使用 POST 进行页面间导航。这不仅是糟糕的用户体验(URL 不会改变,在浏览器历史记录中后退/前进时的行为不直观),而且也不利于 SEO(搜索机器人不会为 POST 建立索引)。

您需要用 h:outputLink 替换它,或者,正如您发现的,如果您不需要任何 JSF 风格的功能,则需要用一个简单的 元素替换它全部。

至于最后一个问题,即定向到错误的 URL(具有重复的路径):当您使用 h:outputLink 时,这个问题就可以解决。然后,JSF 将考虑当前上下文路径。

<h:commandLink action="user/Profile" />

A h:commandLink and h:commandButton fires a HTTP POST request (by the h:form) to the current page which in turn forwards to the given resource.

You don't want to use POST for page-to-page navigation. It's not only bad user experience (URL doesn't change, unintuive behaviour when going back/forward in browser history), but also not SEO friendly (searchbots doesn't index POST).

You need to replace it by h:outputLink or, as you found out, by a simple <a> element if you don't need any JSF-ish features at all.

As to your last problem of going directed to the wrong URL (with duplicated path): this is solved when you use h:outputLink. JSF will then take the current context path into account.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文