Tuesday 15 March 2011

spring mvc - Conditionally setting the HTTP status without directly manipulating the HttpServletResponse -


How can I easily set up HTTP status codes in the Spring MVC request handler?

I have a request handler who responds to POST requests to create a new resource. If the request is valid, then I want to redirect it to the new resource's URI, a 201 (created) HTTP Returns the status code. If the request is invalid, then I want the user to give an opportunity to correct the error in the submitted form and should not give the status code of 201. Public string processing format (@ModelEtiTuode (value = "name") Last string name, last binding result (value = {"/ MyURI /"}, method = RequestMethod.POST) Binding result) {myValidator.validate (name, binding result); If (binding result. Acreser ()) {getService (). CreateThing (name); Return "Redirect:" + name; } And {return "Newtonview"; }

}

But it does not give correct response status for the issue of redirection.

I'm just a @ responsestats , because there are two potential situations, I'm hoping that there is a clean way. And I want to indicate the name of the name to use, so I can not.

If you want 201 response code, you can return the form when creating the resource and the view name is otherwise Could. If so, you can not use a redirect (http code 301).

No comments:

Post a Comment