如何使用Spring Security在登录表单上保留用户名 [英] How to retain username on login form using spring security

查看:256
本文介绍了如何使用Spring Security在登录表单上保留用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Spring安全性在我们的应用程序中进行身份验证.登录表单具有四个参数(用于用户名,组织,公司和密码的四个输入文本字段).

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.

推荐答案

您是否正在使用Spring MVC?如果是这样,那么如果您在jsp文件中使用spring表单标签,则很容易做到这一点.例如,如果您在表单中有一个名为username的字段,则可能会这样:

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.

如果您不使用Spring MVC,它仍然很容易实现.您只需要在转发到jsp之前将诸如用户名之类的字段值设置为request属性即可.在jsp中,您可以使用您设置的请求属性.

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.

这篇关于如何使用Spring Security在登录表单上保留用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆