问题
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