春季安全。每页显示用户名
我想在登录后存储用户信息,并在每个页面上显示我的登录名和用户名(使用jsp)。如何在 jsp 视图中访问存储登录用户信息的会话 bean?
I want to store user information after logging in and to display my login and username on every page (using jsp). How can I get access in my jsp views to the session bean that would store information of the user that is logged in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 身份验证标签
use the authentication tag
我假设你正在使用 Spring Security。成功登录后,将 UserDetails 对象放入会话中,如下所示(如果登录成功,这通常是您将转发的控制器)
在 JSP 中,您可以访问 UserDetails 对象,如下所示:
I'm assuming you are using spring security. After successful login put the UserDetails object in the session like so (This is usually the controller where you would forward if login was successfull)
In your JSP you can access the UserDetails object, like so:
这几乎与 使用 Spring Security 时,获取 bean 中当前用户名(即 SecurityContext)信息的正确方法是什么?< /a>. Spring 认可的方法是
,但链接的讨论有其他选择。
This is a near duplicate to When using Spring Security, what is the proper way to obtain current username (i.e. SecurityContext) information in a bean?. The Spring endorsed method is
but the linked discussion has alternatives.