如何使用安全性:春天的身份验证标签?

时间:2010-12-28 08:28:01

标签: java spring spring-mvc spring-security

我是春天新手。我想将登录用户的用户名发送到我的控制器。 我尝试使用不起作用的代码......

<form:input path="bidderName" value="<security:authentication property=/"principal.username/"/>" />

在值字段我想获取登录用户的用户名。 请帮忙。先谢谢你。

1 个答案:

答案 0 :(得分:5)

您无需将其发送到Spring Controller。你可以直接从那里访问它。

SecurityContextHolder.getContext().getAuthentication().getName();

您似乎正在尝试将登录用户从JSP表单传递回控制器