Click here to Skip to main content
16,020,261 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a profile page and an update page. First time I hit update I get the error messages, second time I hit update with all fields populated I get this error:

Completed 405 METHOD_NOT_ALLOWED
"ERROR" dispatch for POST "/error", parameters={multipart}


Here is the log:
2022-03-06 19:34:16.160 DEBUG 12260 --- [nio-8080-exec-8] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
2022-03-06 19:34:16.170 DEBUG 12260 --- [nio-8080-exec-8] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2022-03-06 19:34:16.214 DEBUG 12260 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : GET "/css/style.css", parameters={}
2022-03-06 19:34:16.215 DEBUG 12260 --- [nio-8080-exec-9] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [static/], ServletContext [/]]
2022-03-06 19:34:16.220 DEBUG 12260 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2022-03-06 19:34:16.220 DEBUG 12260 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : GET "/images/undraw_profile_1.svg", parameters={}
2022-03-06 19:34:16.221 DEBUG 12260 --- [nio-8080-exec-3] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [static/], ServletContext [/]]
2022-03-06 19:34:16.223 DEBUG 12260 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2022-03-06 19:34:16.248 DEBUG 12260 --- [io-8080-exec-10] o.s.web.servlet.DispatcherServlet        : GET "/images/1915.jpg", parameters={}
2022-03-06 19:34:16.249 DEBUG 12260 --- [io-8080-exec-10] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [static/], ServletContext [/]]
2022-03-06 19:34:16.256 DEBUG 12260 --- [io-8080-exec-10] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2022-03-06 19:34:40.242 DEBUG 12260 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : PATCH "/users/profile/update/", parameters={multipart}
2022-03-06 19:34:40.245  WARN 12260 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PATCH' not supported]
2022-03-06 19:34:40.247 DEBUG 12260 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed 405 METHOD_NOT_ALLOWED
2022-03-06 19:34:40.247 DEBUG 12260 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for POST "/error", parameters={multipart}
2022-03-06 19:34:40.248 DEBUG 12260 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
2022-03-06 19:34:40.256 DEBUG 12260 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, text/html;q=0.8]
2022-03-06 19:34:40.264 DEBUG 12260 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 405
2022-03-06 19:34:40.304 DEBUG 12260 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet        : GET "/css/style.css", parameters={}
2022-03-06 19:34:40.305 DEBUG 12260 --- [nio-8080-exec-7] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [static/], ServletContext [/]]
2022-03-06 19:34:40.309 DEBUG 12260 --- [nio-8080-exec-7] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2022-03-06 19:34:40.340 DEBUG 12260 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : GET "/images/undraw_profile_1.svg", parameters={}
2022-03-06 19:34:40.341 DEBUG 12260 --- [nio-8080-exec-5] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [static/], ServletContext [/]]
2022-03-06 19:34:40.344 DEBUG 12260 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Completed 200 OK



The Controllers:

Java
@GetMapping("/profile/update/{id}")
public String showUpdateForm(@PathVariable Long id, Model model) {
    ProfileUpdateServiceModel updateServiceModel = this.userService.getProfileUpdateServiceModelById(id);
    ProfileUpdateBindingModel updateBindingModel = this.mapper.map(updateServiceModel, ProfileUpdateBindingModel.class);
    if (!model.containsAttribute("updateBindingModel")) {
        model.addAttribute("updateBindingModel", updateBindingModel);

    }

    return "update-profile";
}




Java
@PatchMapping("/profile/update/{id}")
public String update(@PathVariable Long id,@Valid ProfileUpdateBindingModel updateBindingModel, BindingResult br, RedirectAttributes rAtt){
if (br.hasErrors()) {
    rAtt
    .addFlashAttribute("updateBindingModel", updateBindingModel)
   .addFlashAttribute("org.springframework.validation.BindingResult.updateBindingModel", br);
   return "redirect:/users/profile/update/" + id;
}
   return "redirect:/users/profile/" + id;
}


In profile.html I have a button like this:
HTML
<pre>  <pre><form
   th:method="GET"
   th:action="@{/users/profile/update/{id}(id=*{userId})}">
   <div class="col-md-6 offset-md-3 p-5">
      <button type='submit' class="btn btn-primary">Update</button>
   </div>
</form>


And in update-profile it is like this:
HTML
 <div class="col-xl-6 col-md-12">
<form
   th:object="${updateBindingModel}"
   th:action="@{/users/profile/update/{id}(id=*{userId})}"
   th:method="PATCH"
   enctype="multipart/form-data">


What I have tried:

Whole day was researching about this but could not find much info. I think my get and post mappings match with those in the form. Not really sure what to look for.
Posted
Comments
Richard Deeming 7-Mar-22 3:58am    
Your PATCH mapping is defined against the path /profile/update/{id}.

Your log file shows that you are making a PATCH request to /profile/update/, with no id parameter in the URL.
Member 15471521 7-Mar-22 9:27am    
I came to the same conclusion, but what confuses me is that this happens the second time I hit update. So I hit update once and I get the error messages, then I hit again update, expecting to get the same error messages and I get this error. So if it finds the id the first time why is it not finding it the second time? When I debug it gets to the GET mapping, then PATCH then again GET and shows errors. Then update -> error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900