Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
Request parameter with thymeleaf

In a Spring Boot web app, User wants to reset his password, so he enters Reset password page. Now I want to let him type his email address, push Reset and I want to redirect to myapp/resetPassword?email=HIS_EMAIL to handle password reset.

MY code:

@RequestMapping(value = "/resetPassword", method = RequestMethod.GET)
public String resetPasswordForm(Model model){
    model.addAttribute("email", new String());
    return "resetPassword";
}

@RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
public String resetPassword(@RequestParam("email") String email) {
    User user = userService.findUserByEmail(email);
    //playing with logic
    return "redirect:/";
}

How can I achieve it on my thymeleaf page? I tried something like this:

<form th:action="@{/resetPassword(email=${email})}" method="post">
    <input type="email" th:field="${email}" th:placeholder="Email" />
        <div class="clearfix">
            <button type="submit">Reset</button>
        </div>
</form>

Unfortunately my email is always null. Can somebody help?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

"th:field" is for Entity-Beans only. This should work:

@GetMapping(value = "/resetPassword")
public String resetPassword(@RequestParam(value="email",required=false) String email) {
    if(email==null)
        return "resetPassword";
    User user = userService.findUserByEmail(email);
    //playing with logic
    return "redirect:/";     
}

<form th:action="@{/resetPassword}" method="get">
    <input type="email" th:name="email" th:placeholder="Email" />
    <div class="clearfix">
        <button type="submit">Reset</button>
    </div>
</form>

And don't forget: Thymeleaf is not Javascript. It is rendered on Server. Things like @{/resetPassword(email=${email})} would output e.g. /resetPassword?email=anValueYouAddedToModelInController

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda