以RedirectView#render进行跳转分析
3.1 下图显示以是否兼容http1.0(http10Compatible) 进行区分获取Location
(1)默认是兼容http1.0,故response.sendRedirect(encodedURL);
(2)response.sendRedirect(encodedURL)最终会触发到tomcat的org.apache.catalina.connector.Response的sendRedirect方法
public void sendRedirect(String location, int status) throws IOException {
locationUri = toAbsolute(location);
setStatus(status);
setHeader("Location", locationUri); //设置跳转的location
}
3.2 跳转Location生成的入口:org.apache.catalina.connector.Response#toAbsolute
// 从request中获取协议、IP、端口信息,然后和设置的相对路径拼接起来
protected String toAbsolute(String location) {
String scheme = request.getScheme();
String name = request.getServerName();
int port = request.getServerPort();
redirectURLCC.append(scheme, 0, scheme.length());
redirectURLCC.append("://", 0, 3);
redirectURLCC.append(name, 0, name.length());
if ((scheme.equals("http") && port != 80)
|| (scheme.equals("https") && port != 443)) {
redirectURLCC.append(':');
String portS = port + "";
redirectURLCC.append(portS, 0, portS.length());
}
redirectURLCC.append(location, 0, location.length());
}