我是 Spring 的新手。我想将登录用户的用户名发送到我的 Controller 。 我尝试了以下不起作用的代码...
<form:input path="bidderName" value="<security:authentication property=/"principal.username/"/>" />
在值字段我想获取登录用户的用户名。 请帮忙。在此先感谢您。
最佳答案
您不需要将它发送到您的 Spring Controller 。实际上,您可以直接从那里访问它。
SecurityContextHolder.getContext().getAuthentication().getName();
您似乎正试图将登录用户从 JSP 表单传回您的 Controller
关于java - 如何使用安全 :authentication tag in Spring? 获取用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4544687/