How to retain username on login form using spring security

佐手、 提交于 2019-12-25 11:26:14

问题


We are using spring security for the authentication in our application. The login form has four parameters (four input text fields for username, organization, company and password).

When wrong password is entered all the other input parameters are also cleared from the login form. How do we retain those values? We do not want user to enter the other details again if the authentication fails.


回答1:


Are you using Spring MVC? If so it is very easy to do that if you use the spring form tags in jsp files. For example if you have a field called username in the form you could something like this:

<form:form>
  <form:input path="username" />
</form:form>

On the Controller side, if you show the same view again, the the form will have the username field filled with the value from the last time.

If you are not using Spring MVC, it is still easy to do. You just need to set the field value such as username to the request attribute before forwarding to jsp. From jsp you can use the request attributes that you set.



来源:https://stackoverflow.com/questions/8921383/how-to-retain-username-on-login-form-using-spring-security

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!