Sunday, 15 May 2011

java - redirect from method with http DELETE type to method with GET type -



java - redirect from method with http DELETE type to method with GET type -

i send request using jquery ajax type "delete". @ server side have approprite handle method looks this:

@requestmapping(value = "/{id}", method = requestmethod.delete) public string delete(@requestparam("hotel") string hotelcode, @pathvariable long id, model model){ //delete operation homecoming "redirect:/hoteltaxesandcharges?hotel="+hotelcode; }

and method want redirect phone call after delete looks this

@requestmapping(method = requestmethod.get) public string getall(@requestparam("hotel") string hotelcode, model model){ //logic homecoming 'getall'; }

so when phone call delete method during execution i'm getting error "you can redirect jsp using set or head methods". found solution using hiddenhttpmethodfilter, result code looks little messy , need send request using post , adding additional parameter (_method) requst custom request type.

so question there other solution delete/redirect/get transformation.

sorry bad english

update

so can redirects using delete too. , if alter delete post this:

what happens normal if not need :

you submit delete request ajax spring controller receives , answers "redirect:/.../hotel..." spring viewresolver sends redirect response code 302 , right location header browser uses precedent method , new location (normal 302) issuing delete (when expected get) spring dispatcherservlet receives delete /.../hotel... when @requestmapping method=get spring dispatcherservlet correctly states no controller defined , issues error

all confirmed wireshark traces

it works when send post request, because compatibility http 1.0, major browsers utilize redirection next post if status 303

there immediate workaround : allow method redirected url take delete in add-on get. not expensive, not nice.

you manage redirection on client side : send 200 code received ajax, , allow ajax redirection

the lastly solution consist in using 303 code explicitely inquire browser issue independently of previous method. can hardcode having controller request take httpservletresponse paremeter , homecoming null. manually add together location header , 303 status code.

but can configure internalresourceviewresolver homecoming 303 codes instead of 302 setting redirecthttp10compatible attribute false. simple declare bean in servlet application context , spring utilize it. loose compatibility older browsers not back upwards http 1.1 , 303 status code.

java spring-mvc

No comments:

Post a Comment