如何通过JSF导航规则重定向或输入URL来检测用户是否已到达页面? [英] How to detect whether user have reached a page by JSF navigation rule redirect or by typing the URL?

查看:95
本文介绍了如何通过JSF导航规则重定向或输入URL来检测用户是否已到达页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JSF中是否可以使用某种方式来确定用户是通过JSF的导航规则到达页面还是用户直接键入URL即可到达该页面?

Is there any way in JSF which can be used to find out whether an user reached a page by the Navigation rule of the JSF or user has typed the URL directly to reach that page?

实际上,我想通过直接在浏览器中键入URL来阻止用户直接进入页面,而我想限制用户使用应用程序导航栏来进入页面.

Actully I want to prevent user to go to a page directly by typing the URL for that directly in the Browser, rather I want to restrict the user to use the application navigation bar to go to an page.

推荐答案

有一种 a 方式:检查referer标头的存在(是,拼写错误).

There is a way: check the presence of the referer header (yes, with the misspelling).

if (externalContext.getRequestHeader("referer") == null) {
    // User has most likely accessed the page by directly typing the URL.
}

<h:panelGroup rendered="#{empty header['referer']}">
    <!-- User has most likely accessed the page by directly typing the URL. -->
</h:panelGroup>

对于那些整齐地使用了网页中的链接,但使用了过分热情的代理/防火墙/安全软件的用户而言,这将失败,该软件完全隐藏了referer标头.

This will however fail for users who have neatly used the link in your webpage, but are using some overzealous proxy/firewall/security software which hides the referer header altogether.

您可能需要考虑将页面从不直接供用户使用,方法是将其放置在/WEB-INF文件夹中,并将其用作由POST请求执行的条件包含(如有必要,请使用ajax).例如

You might want to consider to make the page never directly available to users by placing it in /WEB-INF folder and using it as a conditional include which is executed by a POST request (if necessary with ajax). E.g.

<h:form>
    <h:commandLink action="#{bean.showPage}" />
</h:form>

<h:panelGroup rendered="#{bean.showPage}">
    <ui:include src="/WEB-INF/includes/foo.xhtml" />
</h:panelGroup>

这篇关于如何通过JSF导航规则重定向或输入URL来检测用户是否已到达页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆