从零开始手写Tomcat的教程5节---servlet容器
- 前言
- Container接口
- 管道任务
- Pipeline类
- Valve接口
- ValveContext接口
- Contianed接口
- Wrapper接口
- Context接口
- Wrapper应用程序
- SimpleLoader类
- SimplePipeline类
- SimpleWrapperValve类
- ClientPLoggerValve类
- HeaderLoggerValve类
- BootStrap1类
- 运行应用程序
- 总结
- Context应用程序
- 思路整理
- SimpleContextValve类
- SimpleContextMapper类
- SimpleContext类
- BootStrap2
- 总结
前言
servlet容器是用来处理servlet资源相关请求的,并为web客户端填充response对象的模块。
servlet容器是Container接口的实例。在Tomcat中,共有4种类型的容器,分别是: Engine,Host,Context和Wrapper。
本章将对Context和Wrapper两种servlet容器进行讲解,Engine和Host两类将在后面的系列中进行介绍。
本章首先介绍Container接口,讨论servelt容器中的管道机制,然后,介绍Context接口和Wrapper接口。
Container接口





这里管道的实现是tomcat一个非常重要的特性
管道任务









个人认为这样做主要是为了解耦,将负责挨个调用阀门的ValveContext内部类,从Pipeline类中抽离出来

Pipeline类

提前说一下:这里基础阀指的是日志记录器,监听器等阀门,而基础阀指的是最终处理请求的容器对象
Valve接口

ValveContext接口


Contianed接口

Wrapper接口

Context接口

Wrapper应用程序

SimpleLoader类


SimplePipeline类


SimpleWrapperValve类


ClientPLoggerValve类


HeaderLoggerValve类


BootStrap1类

基础阀在SimpleWrapper构造函数中被设置


运行应用程序

总结
这里对上面的程序做一个图解:

Context应用程序






思路整理

SimpleContextValve类


SimpleContextMapper类
SimpleContextMapper类实现Tomcat 4中的Mapper接口,需要和SimpleContext的实例相关联


RequestURI包含了Context-path,releativePath指的就是Servlet对应的资源路径
SimpleContext类

BootStrap2





总结



