文档介绍:Tomcat源码分析(五)--容器处理连接之servlet的映射
本文所要解决的问题:一个http请求过来,容器是怎么知道选择哪个具体servlet?
我们知道,一个Context容器表示一个web应用,一个Wrapper容器表示一个a]
public Container map(Request request, boolean update) {
// Identify the context-relative URI to be mapped
String contextPath =
((HttpServletRequest) ()).getContextPath();
String requestURI = ((HttpRequest) request).getDecodedRequestURI();
String relativeURI = (());
// Apply the standard request URI mapping rules from the specification
Wrapper wrapper = null;
String servletPath = relativeURI;
String pathInfo = null;
String name = null;
// Rule 1 -- Exact Match
if (wrapper == null) {
if (debug >= 2)
(" Trying exact match");
if (!(("/")))
name = (relativeURI);
if (name != null)
wrapper = (Wrapper) (name);
if (wrapper != null) {
servletPath = relativeURI;
pathInfo = null;
}
}
// Rule 2 -- Prefix Match
if (wrapper == null) {
if (debug >= 2)
(" Trying prefix match");
servletPath = relativeURI;
while (true) {
name = (servletPath + "/*");
if (name != null)
wrapper = (Wrapper) (name);
if (wrapper != null) {
pathInfo = (());
if (() == 0)
pathInfo = null;
bre