springmvc直接访问 上下文路径 302 后路径更改并跳转源码解析

【问题现状】

application.yml 配置如下属性:

yaml 复制代码
server:
  servlet:
    context-path: /learning

直接访问:http://localhost:8888/learning 路径时,会返回302的响应状态;并跳转路径:http://localhost:8888/learning/ (原路径后多了个斜杠/)

源码分析:

org.apache.tomcat.util.net.NioEndpoint.SocketProcessor#doRun

org.apache.coyote.AbstractProtocol.ConnectionHandler#process

org.apache.coyote.AbstractProcessorLight#process

org.apache.coyote.http11.Http11Processor#service

org.apache.catalina.connector.CoyoteAdapter#service

此时 status 还为 200,执行过后,status 变为 302,如下所示:

详细看 org.apache.catalina.connector.CoyoteAdapter#postParseRequest 方法:

再深入分析 request.getMappingData().redirectPath 的值是怎么来的:

org.apache.catalina.mapper.Mapper#map

org.apache.catalina.mapper.Mapper#internalMap

org.apache.catalina.mapper.Mapper#internalMapWrapper

扩展学习:

1、Tomcat源码分析:HTTP请求处理过程

2、SpringBoot Tomcat 工作流程

相关推荐
一点程序10 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
奋进的芋圆11 小时前
Spring Boot 实现三模安全登录:微信扫码 + 手机号验证码 + 邮箱验证码
spring boot·redis·微信
怪兽源码12 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
m0_7400437314 小时前
【无标题】
java·spring boot·spring·spring cloud·微服务
重整旗鼓~14 小时前
1.外卖项目介绍
spring boot
一点技术16 小时前
基于SpringBoot的选课调查系统
java·spring boot·后端·选课调查系统
shuair16 小时前
redis实现布隆过滤器
spring boot·redis·bootstrap
RANCE_atttackkk16 小时前
Springboot+langchain4j的RAG检索增强生成
java·开发语言·spring boot·后端·spring·ai·ai编程
好好研究18 小时前
Spring Boot - Thymeleaf模板引擎
java·spring boot·后端·thymeleaf
她说..18 小时前
策略模式+工厂模式实现单接口适配多审核节点
java·spring boot·后端·spring·简单工厂模式·策略模式