1

this is my htmpl page where I got an error: unlock.html

<p th:text="${successMsg}" class="text-success">

    <p th:text="${errorMsg}" class="text-danger">

    <form th:action="@{/unlock}" th:object="${unlock}" th:method="POST">

        <div class="form-outline mb-6">
            <h6>Your Email :<p th:text="${unlock.email}"/> </h6>
            <input type="hidden" th:field="${unlock.email}"/>
        </div>

        <div class="form-outline mb-4">
        <input type="password" id="form2Example22" class="form-control" th:field="*{tempPwd}"/>
        <label class="form-label" for="form2Example22">Temporary Password</label>
        </div>

        <div class="form-outline mb-4">
            <input type="password" id="form2Example23"
                class="form-control" th:field="*{newPwd}"/> 
                <label class="form-label" for="form2Example23">New Password</label>
        </div>
        
        <div class="form-outline mb-4">
            <input type="password" id="form2Example24"
                class="form-control" th:field="*{confPwd}"/> 
                <label class="form-label" for="form2Example24">Confirm Password</label>
        </div>

        <div class="text-center pt-1 mb-5 pb-1">
            <input type="submit" value="unlock" class="btn btn-primary btn-block fa-lg gradient-custom-2 mb-3"/>
        </div> </form>

This is controller:

@GetMapping("/unlock")
    public String unlockPage(@RequestParam String email, Model model) {
        
        UnlockForm unlockFormObj = new UnlockForm();
        unlockFormObj.setEmail(email);
        
        model.addAttribute("unlock",unlockFormObj);
        
        return "unlock";
    }
    
    @PostMapping("/unlock")
    public String unlockUserAccount(@ModelAttribute("unlock)") UnlockForm unlock, Model model) {

        //validate user entered password and current password should same
        if (unlock.getNewPwd().equals(unlock.getConfPwd())){

            //if valid then unlock the account
            boolean status = studentService.unlockAccount(unlock);

            if (status){
                model.addAttribute("successMsg", "Your account unlocked successfully..");
            }else {

                model.addAttribute("errorMsg","Given temporary password is incorrect, check email once..");
            }
        }else {

            //if not valid then send error msg as response to the client
            model.addAttribute("errMsg", "New Password and Confirm password must be same");
        }

        System.out.println(unlock);

        return "unlock";
    }

Data correctly store in the database but as response message not sending to UI.

I was trying to unlock the user account by clicking the link which was received in my email.

When I inserting the temp password and entering new password, It will be stored in the database but success message not going as response to UI.

The error is coming:

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/unlock.html]")
    org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
    org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
    org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
    org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
    org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
    org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:366)
    org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:190)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1406)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1150)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1089)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:555)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:623)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
    org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
James Z
  • 12,209
  • 10
  • 24
  • 44
Pramod Lad
  • 21
  • 2
  • Please suggest error – Pramod Lad Jun 19 '23 at 18:33
  • Great job on providing a detailed explanation of your issue, including both your HTML and controller code. It's clear that you've put a lot of thought into your application and are making good use of Spring and Thymeleaf. Keep up the good work! Remember, encountering errors is a normal part of the development process and each one is a learning opportunity. Don't hesitate to ask more questions if you encounter further issues. Happy coding! – Perch Hakobyan Jun 19 '23 at 21:15
  • @PramodLad provide what is the parsing error. It usually will come when you have some issues with your template file like syntax problems or any object which you declared is not present in the supplied object from java to thymeleaf engine. It will be better if you provide the exact parsing error as well as minimal reproducible example. You can use github or any platform. – Rishal Jun 30 '23 at 12:49

0 Answers0