如何尝试将 sec:loggedInUserInfo 写入 gsp 中的变量中
我想获取 sec:loggedInUserInfo 的值并尝试进入名为 user 的变量。
我的代码如下所示:
<sec:loggedInUserInfo field="username" />
<%
def user = *value of field loggedInUserInfo *
%>
可以这样做吗?
I want to get value of sec:loggedInUserInfo and attempt into a variable named user.
My code looks like this:
<sec:loggedInUserInfo field="username" />
<%
def user = *value of field loggedInUserInfo *
%>
Is it possible for doing that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不确定我们是否可以直接使用该标签,我之前找不到它,所以我为此目的制作了自定义标签
}
I am not sure if we can use that tag directly, I couldn't find it earlier, so I have made my custom tag for this purpose
<m:userName id="${session.SPRING_SECURITY_CONTEXT?.authentication?.principal?.id}"/>
}
我创建了一个标记库作为loggedinUser,它被添加到gsp页面上:
在我的项目中的每个gsp顶部显示登录的用户名。在自定义标签库中,我的代码如下:
所以它在每个页面上显示为:欢迎用户名[注销]!
I have created one taglib as loggedinUser which is added on gsp page as :
Which is showing logged In username on top of each gsp in my project. In custom tag library my code is as follows :
So it's showing on each page as : Welcome USERNAME[Logout] !
这更简单并且对我来说效果很好:
This is simpler and works fine for me:
分配 到您可以使用的变量:(
另请参阅 自定义用户详细信息)
To assign any field of the UserDetails instance referred to by <sec:loggedInUserInfo> to a variable you can use:
(see also Custom User Details)
如果您想要 gsp 中的用户对象,只需将其作为模型映射的一部分从控制器传回即可。在控制器动作中做
If you want the user object in the gsp, just pass it back as part of the model map from the controller. in a controller action do