#Request method 'POST' is not supported - SpringMVC with Thymeleaf

1 messages · Page 1 of 1 (latest)

lofty robin
#

Problem in the topic

boreal lodgeBOT
#

<@&1004656351647117403> please have a look, thanks.

boreal lodgeBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

lofty robin
#
    public String viewRegisterPage() {
        return "register";
    }

    @ModelAttribute("user")
    public UserRegistrationDTO userRegistrationDTO() {
        return new UserRegistrationDTO();
    }

    @PostMapping("/register")
    public String registerAccount(@ModelAttribute("user")UserRegistrationDTO registrationDTO) {
        userService.registerUser(registrationDTO);
        return "redirect:/register?success";
    }```
boreal lodgeBOT
lofty robin
#
            <form th:action="@{/register}" method="post" th:object="${user}" class="form">
                <h2>Zarejestruj się</h2>

                <input type="firstname" class="box" , placeholder="Wpisz imię" th:field="*{firstName}">
                <input type="lastname" class="box" , placeholder="Wpisz nazwisko" th:field="*{lastName}">
                <input type="email" name="email" class="box" placeholder="Wpisz email" th:field="*{email}">
                <input type="password" name="password" class="box" placeholder="Wpisz hasło" th:field="*{password}">
                <input type="submit" value="Logowanie" id="submit">
                <input
                        type="hidden"
                        th:name="${_csrf.parameterName}"
                        th:value="${_csrf.token}" />
            </form>```
boreal lodgeBOT
lofty robin
#

2023-01-31T20:32:05.313+01:00 WARN 24232 --- [nio-8080-exec-8] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' is not supported]

drifting scroll
#

What if you remove that redirect. Put a log in the post mapping does it hit it at all

lofty robin
#

I can't fix this, i researched tones of stackoverflow sites with the same problem and users used method get instead of the post method. In my example i use post method and its correct.

#

I'm using Spring Security too, maybe there is the problem, but i deleted the EnableWebSecurity annotation and the problem still exists.

lofty robin
#

It was the problem with the commas in the first two inputs and probably problem with missing name html attribute.