Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 在Thymeleaf模板中使用SPRING\u SECURITY\u LAST\u用户名_Spring Mvc_Login_Spring Security_Thymeleaf - Fatal编程技术网

Spring mvc 在Thymeleaf模板中使用SPRING\u SECURITY\u LAST\u用户名

Spring mvc 在Thymeleaf模板中使用SPRING\u SECURITY\u LAST\u用户名,spring-mvc,login,spring-security,thymeleaf,Spring Mvc,Login,Spring Security,Thymeleaf,我有一个由ThymeLeaf提供并由SpringSecurity支持的登录表单。如果发生身份验证错误,我希望用户名字段预先填充用户在上次尝试时输入的值。Spring Security为此提供了Spring\u Security\u LAST\u用户名,但我在文档和在线搜索中并没有找到如何通过ThymeLeaf公开该用户名。以下是相关文件的简化版本: 我的安全XML文件: <beans xmlns="http://www.springframework.org/schema/beans"

我有一个由ThymeLeaf提供并由SpringSecurity支持的登录表单。如果发生身份验证错误,我希望用户名字段预先填充用户在上次尝试时输入的值。Spring Security为此提供了Spring\u Security\u LAST\u用户名,但我在文档和在线搜索中并没有找到如何通过ThymeLeaf公开该用户名。以下是相关文件的简化版本:

我的安全XML文件:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:sec="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.1.xsd">
    <sec:http auto-config="true">
        <sec:intercept-url pattern="/login/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
        <sec:form-login login-page="/login" authentication-failure-url="/login/fail" default-target-url="/"/>
        <sec:logout />
    </sec:http>
    <sec:global-method-security secured-annotations="enabled"/>
</beans>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <head th:include="template::head"></head>
    <body class="login">
        <nav th:include="template::nav"></nav>
        <div>
            <h2>Log in</h2>
            <div>
                <div th:if="${loginFail}" class="error">
                    Username/password incorrect.
                </div>
                <form id="login" th:action="@{/j_spring_security_check}" method="POST">
                    <dl>
                        <dt>Username</dt>
                        <dd><input type="text" id="j_username" name="j_username" />@mshare.net</dd>
                        <dt>Password</dt>
                        <dd><input type="password" id="j_password" name="j_password" /></dd>
                    </dl>
                    <input type="submit" value="Log in" />
                </form>
            </div>
        </div>
    </body>
</html>
@RequestMapping(value = "/login/fail")
public String loginError(Model model) {
    model.addAttribute("loginFail", Boolean.TRUE);
    return "login";
}