java - 从用户处获取密码值,我想在 url 路径中使用此密码,我使用 thymeleaf 作为模板引擎

标签 java spring thymeleaf template-engine

我在从用户处获取密码值时遇到问题,我想在 url 路径中使用此密码,我使用 thymeleaf 作为模板引擎。

这是我的 Controller

    @RequestMapping(value = "/findEvent/{passcode}", method = RequestMethod.POST)
    public String findEvent(@PathVariable("passcode") String passcode,
                            final RedirectAttributes redirectAttributes, Model model) {

        Event event=eventService.findByPassCode(passcode);
        List<Question> questions=questionService.findQuestionsByPasscode(passcode);

        model.addAttribute("questions",questions);

        return "questions";
    }

这些是我的 html 页面

addEvent.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <title>Hello World!</title>
</head>
<body>
<form method="post" th:action="@{/eventSave}" th:object="${eventRegister}">
    Name:<br>
    <input type="text" th:field="*{eventName}"><br>
    Passcode:<br>
    <input type="text" th:field="*{eventPasscode}"><br>

    <input type="submit" value="Submit">
</form>
</body>
</html>

密码.html

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="post" th:action="@{/findEvent/{passcode}}">

    Passcode:<br>
    <input type="text"  th:text="*{passcode}" ><br>

    <input type="submit" value="Submit">
</form>
</body>
</html>

问题.html

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div class="col-12">
    <table class="table table-bordered">
        <tr>
            <th>Question </th>
            <th>Votes </th>

        </tr>
        <tr th:each="questions : ${questions}" th:object="${question}">
            <td th:text="*{text} "></td>
            <td th:text="*{voteValue} "></td>

            <a th:href="@{/voteQuestion/{id} (id=${question.questionId})}">Vote the question</a>
        </tr>
    </table>
</div>

and this is my result http://localhost:8080/findEvent/%7Bpasscode%7D

最佳答案

如果您希望表单操作 URL 包含表单本身的值,则需要 onSubmit处理程序以更新表单字段中的 URL。

表单值仅自动包含在 POST正文中请求,或作为 GET查询参数请求。

任何其他与 JavaScript 代码相关的事情。

关于java - 从用户处获取密码值,我想在 url 路径中使用此密码,我使用 thymeleaf 作为模板引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58578730/

相关文章:

java - 使用 gson 将结果集转为 json

java - 在 Spring 3.1 中使用基本身份验证的 RestTemplate

Spring WS (DefaultWsdl11Definition) 带有 void 的 HTTP 状态码

java - 迭代 Thymeleaf 中的 map 列表

java - 上传文件时出现 NullPointerException

java - 如果我在java中将一个方法的变量声明为类的成员变量,我可以在另一种方法中访问它的值吗?

java - 检查整数是否太大

java - 如何在 cloudfoundry 或其他地方部署 appfuse?

spring-boot - 如何在 thymeleaf 模板名称处发送 html 内容

javascript - jquery加载函数不调用Spring Boot Controller 来替换thymeleaf模板片段