在每一页上显示用户名

在每一页上显示用户名

本文介绍了春季安全.在每一页上显示用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在登录后存储用户信息,并在每个页面上显示我的登录名和用户名(使用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?

推荐答案

使用身份验证标签

当然,没有必要使用 JSP标签用于这种情况,并且 有些人宁愿少存钱 在视图中尽可能的逻辑.你可以 访问身份验证对象 您的MVC控制器(通过调用 SecurityContextHolder.getContext().getAuthentication()) 并将数据直接添加到您的 用于通过视图呈现的模型.

Of course, it isn't necessary to use JSP tags for this kind of thing and some people prefer to keep as little logic as possible in the view. You can access the Authentication object in your MVC controller (by calling SecurityContextHolder.getContext().getAuthentication()) and add the data directly to your model for rendering by the view.

这篇关于春季安全.在每一页上显示用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:39