Forward method with type DELETE http to method with type GET

I am sending my request using jquery ajax with type DELETE. On the server side, I have a suitable descriptor method that looks like this:

   @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String delete(@RequestParam("hotel") String hotelCode, @PathVariable Long id, Model model){
        //delete operation
        return "redirect:/HotelTaxesAndCharges?hotel="+hotelCode;
    }

and the method to which I want to redirect my call after deletion is as follows

@RequestMapping(method = RequestMethod.GET)
public String getAll(@RequestParam("hotel") String hotelCode, Model model){
    //logic
    return 'getAll';
}

therefore, when I call the delete method at runtime, I get the error "you can redirect to JSP using only the GET PUT or HEAD methods". I found a solution using HiddenHttpMethodFilter, but the result code looks a bit dirty, and I need to send a request using POST and add an additional parameter (_method) to request it using a custom request type.

So, I have a question, is there any other solution for converting DELETE / REDIRECT / GET.

UPDATE enter image description here

delete. , delete , :

enter image description here

+4
1

, , :

  • DELETE ajax
  • Spring "redirect:/.../Hotel..."
  • Spring ViewResolver 302
  • ( 302), DELETE ( )
  • Spring DispatcherServlet DELETE /.../Hotel..., @RequestMapping = GET
  • Spring DispatcherServlet ,

,

, POST, HTTP 1.0 GET POST, , 303

: URL DELETE GET. , .

: 200, ajax, ajax

303, GET . , HttpServletResponse . Location 303.

InternalResourceViewResolver 303 302, redirectHttp10Compatible false. bean , Spring . , HTTP 1.1 303.

+4

Source: https://habr.com/ru/post/1545675/


All Articles