2

My problem is I have thymeleaf template for reset password and I want passwords post than json data (actualy post than form data) to my spring boot server. How can I do it?

My rest controller:

@PostMapping(value = "/save-new-password")
public String saveStudent(@Valid @RequestBody NewPasswordDTO newPasswordDTO) {
    return "OK";
}

Part from my reset-password-page.html:

<body>
    <form th:action="@{/save-new-password}" th:object="${newPasswordDTO}" method="post">
        <div class="box">
            <h1>RESET PASSWORD</h1>
            <input class="password" name="newPassword" type="password" placeholder="New password" th:field="*{newPassword}">
            <input class="password" name="confirmPassword" type="password" placeholder="Confirm password" th:field="*{confirmPassword}">
            <input class="button" type="submit" value="RESET"/>
        </div>
    </form>
</body>
Adam Barča
  • 51
  • 1
  • 10
  • This is something that Thymeleaf doesn't really have anything to do with. Just search for ways to submit a form as JSON using JavaScript. Like this for example: https://stackoverflow.com/a/22195193/4126893 – Metroids Jun 25 '22 at 17:01
  • Is your question how to combine Thymeleaf with AJAX requests? Or do you want to use a regular HTML form (in which case you need to change your controller)? – Wim Deblauwe Jun 26 '22 at 07:57
  • I was wondering if thymeleaf can do it (regular HTML) so that I can do it with javascript, it's clear to me. – Adam Barča Jun 26 '22 at 09:28

0 Answers0