对于一次访问过程,主要有以下几个步骤,假设来自客户的请求为:http://localhost:8080
/test/index.jsp。
(1)请求被发送到本机端口 8080,被在那里侦听的 HTTP Connector 获得;
(2)Connector 把该请求交给它所在的 Service 的 Engine 来处理,并等待来自 Engine
的回应;
(3)Engine 获得请求 localhost/test/ index.jsp,匹配它所拥有的所有虚拟主机 Host;
(4)Engine 匹配到名为 localhost 的 Host(即使匹配不到也把请求交给该 Host 处理,
因为该 Host 被定义为当前 Engine 的默认主机);
(5)localhost Host 获得请求/test/index.jsp,匹配它所拥有的所有 Context;
(6)Host 匹配到路径为/test 的 Context(如果匹配不到就把该请求交给路径名为""的
Context 去处理);
(7)path="/test"的 Context 获得请求/index.jsp,在它的 mapping table 中寻找对应的
Servlet;
(8)Context 匹配到 URL PATTERN 为*.jsp 的 Servlet,对应于 JspServlet 类;
(9)HttpServletRequest 对象和 HttpServletResponse 对象,作为参数调用 JspServlet 的
doGet 或 doPost 方法;
(10)Context 把执行完了之后的 HttpServletResponse 对象返回给 Host;
(11)Host 把 HttpServletResponse 对象返回给 Engine;
(12)Engine 把 HttpServletResponse 对象返回给 Connector;
(13)Connector 把 HttpServletResponse 对象返回给客户浏览器。
这样,一次的请求响应过程结束。
/test/index.jsp。
(1)请求被发送到本机端口 8080,被在那里侦听的 HTTP Connector 获得;
(2)Connector 把该请求交给它所在的 Service 的 Engine 来处理,并等待来自 Engine
的回应;
(3)Engine 获得请求 localhost/test/ index.jsp,匹配它所拥有的所有虚拟主机 Host;
(4)Engine 匹配到名为 localhost 的 Host(即使匹配不到也把请求交给该 Host 处理,
因为该 Host 被定义为当前 Engine 的默认主机);
(5)localhost Host 获得请求/test/index.jsp,匹配它所拥有的所有 Context;
(6)Host 匹配到路径为/test 的 Context(如果匹配不到就把该请求交给路径名为""的
Context 去处理);
(7)path="/test"的 Context 获得请求/index.jsp,在它的 mapping table 中寻找对应的
Servlet;
(8)Context 匹配到 URL PATTERN 为*.jsp 的 Servlet,对应于 JspServlet 类;
(9)HttpServletRequest 对象和 HttpServletResponse 对象,作为参数调用 JspServlet 的
doGet 或 doPost 方法;
(10)Context 把执行完了之后的 HttpServletResponse 对象返回给 Host;
(11)Host 把 HttpServletResponse 对象返回给 Engine;
(12)Engine 把 HttpServletResponse 对象返回给 Connector;
(13)Connector 把 HttpServletResponse 对象返回给客户浏览器。
这样,一次的请求响应过程结束。