Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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

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:添加注册后表单上的错误按钮操作(Spring安全性)_Spring_Spring Mvc_Spring Security - Fatal编程技术网

Spring:添加注册后表单上的错误按钮操作(Spring安全性)

Spring:添加注册后表单上的错误按钮操作(Spring安全性),spring,spring-mvc,spring-security,Spring,Spring Mvc,Spring Security,我用登录页面做了一个例子——Spring安全性 很快: 有一个根页面(“localhost:8080/”)——主页上有一个链接 单击主页上的链接,转到main.html(localhost:8080/main/ 若用户并没有授权,他将被重定向到登录页面 当用户授权时,打开主页面 主页面显示消息并按标记筛选 我在“输入”中输入一个标签,然后按下“搜索”按钮(аааааааа),消息将按标签过滤 当我添加授权时,过滤器已停止工作 这是我的源代码: 根页面-在主页上有链接 <!DOCTYPE H

我用登录页面做了一个例子——Spring安全性

很快:

  • 有一个根页面(“localhost:8080/”)——主页上有一个链接
  • 单击主页上的链接,转到main.html(localhost:8080/main/
  • 若用户并没有授权,他将被重定向到登录页面
  • 当用户授权时,打开主页面
  • 主页面显示消息并按标记筛选
  • 我在“输入”中输入一个标签,然后按下“搜索”按钮(аааааааа),消息将按标签过滤
  • 当我添加授权时,过滤器已停止工作

    这是我的源代码:

    根页面-在主页上有链接

    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Gretting start: Serving Web Content</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <div>Hello, user</div>
        <a th:href="@{/main}">Main page</a>
    </body>
    </html>
    
    我的截图 根页面

    主页

    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title>Gretting start: Serving Web Content</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <div>Hello, user</div>
        <a th:href="@{/main}">Main page</a>
    </body>
    </html>
    
    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>
    <body>
        <div>
            <form method="post">
                <input type="text" name="text" placeholder="Введите сообщение" />
                <input type="text" name="tag" placeholder="Тэг">
                <button type="submit">Добавить</button>     
            </form>
        </div>
        <div>Список сообщений</div>
        <form method="post" action="filter">
            <input type="text" name="filter">
            <button type="submit">Найти</button>
        </form>
        <div th:each = "message : ${messages}">
            <b th:text = "${message.id}"></b>
            <span th:text = "${message.text}"></span>
            <i th:text = "${message.tag}"></i>
        </div>
    </body>
    </html>
    

    当我输入过滤器标签并按下按钮“аааааааа”时(=搜索),我得到一个错误:

    @PostMapping(“/filter”)
    未捕获表单中的操作。我已签入调试器。我无法捕获错误,也不知道为什么会发生这种情况

    我拥有GitHub存储库:

    提交注释“添加消息”-过滤工作


    提交注释“添加远程存储库和登录”-筛选器不起作用,添加登录我发现正在解决。在主页上的表单中,需要添加“th”属性,因为我使用了Thymeleaf so模板引擎。如果使用Thymeleaf,则需要为表单中的哪个自动插入令牌辩护:

    <form method="post" th:action="filter">
       <input type="text" name="filter">
       <button type="submit">Найти</button>
    </form>
    
    
    Найти
    
    我找到了解决方法。在主页上的表单中,需要添加“th”属性,因为我使用了Thymeleaf so模板引擎。如果使用Thymeleaf,则需要为表单中的哪个自动插入令牌辩护:

    <form method="post" th:action="filter">
       <input type="text" name="filter">
       <button type="submit">Найти</button>
    </form>
    
    
    Найти