【问题标题】:Thymeleaf th:href get other input field value?Thymeleaf th:href 获取其他输入字段值?
【发布时间】:2017-01-16 17:37:18
【问题描述】:

这是我的表单,输入字段电子邮件和密码

<form class="form-signin" th:action="@{/login}" method="post">
    <input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus" /> 
    <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required="required" />
    <button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">Sign in</button>
</form>

我想试试 Thymeleaf th:href 发送带参数的 get 请求,

这是我的代码:

<a href="#" th:href="@{/user/forgot_password{email}(email=$(inputEmail).val())}" class="forgot-password"> Forgot the password? </a>

我的 Spring-Boot 控制器如下:

@RequestMapping(value = "/forgot_password", params = {"email!="}, method = RequestMethod.GET)
public @ResponseBody RespCommon forgotPassword(
    @RequestParam(value = "email", required = true) String email) {
    userService.forgotPassword(email);
    return new RespCommon(ResultCode.SUCCESS, "Send forget password mail succeed");
}

但是好像不行,能不能分享一下如何获取其他输入字段的值,非常感谢!

【问题讨论】:

    标签: spring-boot thymeleaf


    【解决方案1】:

    使用链接(因此使用GET 方法)来恢复密码对我来说并不是一个好主意。例如,浏览器或电子邮件客户端可能会跟随它。

    我建议使用看起来像链接的表单(使用 POST 方法)。您可以将电子邮件放在hidden 字段中并将btn btn-link 类添加到提交按钮。要填充电子邮件值,您可以使用 Model.addAttribute() 从控制器中导出值。

    【讨论】:

    • 是的,我也同意 Slava Semushin ... 电子邮件是一个机密问题,对于任何外部获取请求(例如“取消订阅电子邮件”链接)都应该加密。即使您应该使用带有发布请求的表单而不是获取方法@Tommy Yeh
    猜你喜欢
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    • 2017-12-06
    • 2019-07-20
    • 2023-03-31
    • 2021-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多