0

Unable to load html page "addRenewalCode" after successful completion of post request. Code Structure

Controller :

@Controller
public class LoginController {

    @Autowired
    LoginDao loginDao;

    @RequestMapping(value = { "/" }, method = RequestMethod.GET)
    public String login() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login");
        return "login";
    }

    @RequestMapping(path = "/dynamicRenewalCodes", method = RequestMethod.POST)
    public String login(@RequestParam(value = "username") String username,
            @RequestParam(value = "password") String password) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("dynamicRenewalCodeList");
        return "dynamicRenewalCodeList";
    }

    @PostMapping(value = "/addNewRenewalCode")
    public String addNewRenewalCode() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("addRenewalCode");
        return "addRenewalCode";
    }
}

Thymeleaf Html:

<div class="form-group">
    <button type="button" class="btn btn-secondary btn-lg" th:onclick="addRenewalCode()">Add Renewal Code</button>
</div> 

When click on the above button in network console, status code shows 200 and in preview it shows the "addRenewalCode" html page, but the "addRenewalCode.html" page is not able load. Please help !!!

2
  • Could you also add the javascript code of the addRenewalCode () call? In case you don't have any javascript it is normal that you have an issue. In this case it is the JS. That makes the call. Commented Feb 5, 2021 at 7:54
  • I found the error, i.e. I used ajax call so that in ajax call it will get data in the same page and not redirect the request. Commented Feb 10, 2021 at 6:32

1 Answer 1

1

The Thymeleaf tag th:onclick is configured here to call a JS function, addRenewalCode. The browser will be looking for this function when the button is clicked. ThymeLeaf does not autowire the page to the HTML file.

Sign up to request clarification or add additional context in comments.

1 Comment

by changing "th:onclick" to "<a href="/addNewRenewalCode" th:href="@{/addNewRenewalCode}" class="btn btn-secondary btn-lg">Add Renewal Code</a>" is resolve my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.