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

Sag*_*gar 1 java spring spring-mvc spring-security

我是新来的春天.我想将登录用户的用户名发送到我的控制器.我尝试了以下无效的代码......

<form:input path="bidderName" value="<security:authentication property=/"principal.username/"/>" />
Run Code Online (Sandbox Code Playgroud)

在值字段我想获取登录用户的用户名.请帮忙.先感谢您.

chr*_*ris 5

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

SecurityContextHolder.getContext().getAuthentication().getName();
Run Code Online (Sandbox Code Playgroud)

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