简体   繁体   中英

How does a Spring web controller determine the HTTP status code for a redirect

I have a Spring MVC application that has an endpoint that results in a redirect - see code below.

I notice that the HTTP status code that Spring returns for this redirect is a 307 . My question is why does Spring choose to return a 307 rather than a 301 or a 302 .

Is it simply the fact that both GET and POST methods are allowed on this endpoint and 307 is the least permissive response in terms of what a client can do so Spring implements that as the default?

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


@RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.POST})
public String loginAttemptWithoutCookie() {
    return "redirect:" + "/some/other/url;
}

All modern browser will automatically detect 302

302

Actually all HTTP response status codes that are in the 3xx category are considered redirection message, all modern browser will automatically detect 302 Found response code and process the temporarily redirection action automatically

307

actually 307 Internal Redirect from admin side client click on cart items then browser sent a POST to /cart-items.html, then this tells it to redirect the POST at /purchase-selected-items.php

The mean is, Spring is trying to redirect custom defined( view already created by admin ) view without default redirection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM