Jeff
Jeff

Reputation: 8421

Thymleaf: Request method 'POST' not supported

Consider I have the following form, which i send two parameters _id and poID to the controller:

 <form style='float:left; padding:5px; height:0px' th:object="${plant}"  th:method="post" th:action="@{/dashboard/DeliverPlant/{_id}(_id=${plant._id})/{po_id}(po_id=${plant.poID})}">
                        <button class="btn btn-default btn-xs" type="submit">Verify Plant Delivery</button>
                   </form>

And in the controller i have the following form:

 @RequestMapping(method=POST, path="DeliverPlant/{_id}/{po_id}")
     public String DeliverPlant(Model model,@PathVariable("_id") String id,@PathVariable("po_id") String po_id) throws Exception {                  
            Long Id=    Long.parseLong(id);
         System.out.println("po_id is..................."+po_id+ "_id is:   "+id);


            return "dashboard/orders/ShowPOs";
      }

When i send my request, there is no internal error but it complains that

There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported

It seems that it cannot recognize the method. So how can i fix it?

Update:

I also tried this

<form style='float:left; padding:5px; height:0px' th:object="${plant}"  th:method="post" th:action="@{'/dashboard/DeliverPlant/'+{_id}(_id=${plant._id})+'/'+{po_id}(po_id=${plant.poID})}">
                        <button class="btn btn-default btn-xs" type="submit">Verify Plant Delivery</button>
                   </form>

Upvotes: 0

Views: 2827

Answers (2)

0gam
0gam

Reputation: 1423

You return controller in modelAndView.addobject "po", "plant", "??".

You take object value in return page(select page).

"_id" <- ??? ... Anyway

edit path

th:action="@{/dashboard/deliver/plant/__${??.id}__/__${plant.id}__/__${po.id}__ }"

edit controller

@RequestMapping(method = RequestMethod.POST, value ="/deliver/plant/{??.id}/{plant.id}/{po.id}")
public String DeliverPlant(@PathVariable("??.id") int id, @PathVariable("po.id") int poId, @PathVariable("plant.id") int plantId)  {                  

     return "dashboard/orders/ShowPOs"; // <-- break point. 
}

You try debug.

See value.

Upvotes: 0

Monis
Monis

Reputation: 1008

Try

method="POST"

instead of

th:method="POST"

Also, in your Controller class try

@RequestMapping(method=RequestMethod.POST

where RequestMethod is org.springframework.web.bind.annotation.RequestMethod

Upvotes: 1

Related Questions