如何将注销的用户重定向到 Java EE/JSF 中的主页?
我需要只允许登录用户访问我的应用程序的大部分页面。 我正在使用 JSF 2 开发 Java 企业应用程序。 有谁知道我该怎么做?也许有一个配置文件?
我在主页中有一个登录组件,我希望用户在单击页面上除少数项目之外的任何其他项目时被重定向到主页。
I need to allow only logged-in users to most of the pages of my application.
I am developing a Java Enterprise application with JSF 2.
Does anyone know how I can do that? maybe with a config file?
I have a login component in the home page and I would like the users to be redirected to the home page when they click any other items of the page except a few.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有不同的方法可以做到这一点。首先,您可以使用过滤器来控制页面访问,也可以使用侦听 jsf Phases 的阶段侦听器。
我想给你们举两个例子;
你应该将此过滤器添加到 web.xml 中;
阶段监听器示例;
因此,如果您想使用侦听器,您应该将其添加到您的 faces-config.xml 中;
注意:“注销”是在 faces-config 中定义的导航规则
编辑:
导航规则;
您可以像这样将用户置于登录方法中的会话中;
There are different ways to do that . Firstly you can use filters to control page access or you can use phase listeners that listens jsf phases .
I wanna give you two examples for them ;
And you should add this filter to web.xml;
Phase Listener example ;
So if you want to use listener you should add this to your faces-config.xml ;
Note : "logout" is a navigation rule which is defined in faces-config
Edit :
The navigation rule ;
You can put your user to session in login method like that ;
有很多方法可以实现这一目标。最简单也可能是最流行的方法是使用 servlet 过滤器,您可以在这里找到有关这种机制的更多信息:JSF 中的基本安全性
There are many ways to achieve that. The easiest and probably the most popular way would be to use servlet filter, you can find more information about such a mechanism here: Basic Security in JSF