首先所有的请求进入tomcat,都会流经servlet,如果没有匹配到任何应用指定的servlet,那么就会流到默认的servlet。
默认的servlet是配置在$catalina/conf/web.xml里面的。
如下面贴出来所示(由于贴的内容太多了,我把注释去掉了,其实注释是相当重要的):
- <servlet>
- <servlet-name>default</servlet-name>
- <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
- <init-param>
- <param-name>debug</param-name>
- <param-value>0</param-value>
- </init-param>
- <init-param>
- <param-name>listings</param-name>
- <param-value>false</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet>
- <servlet-name>jsp</servlet-name>
- <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
- <init-param>
- <param-name>fork</param-name>
- <param-value>false</param-value>
- </init-param>
- <init-param>
- <param-name>xpoweredBy</param-name>
- <param-value>false</param-value>
- </init-param>
- <load-on-startup>3</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>jsp</servlet-name>
- <url-pattern>*.jsp</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>jsp</servlet-name>
- <url-pattern>*.jspx</url-pattern>
- </servlet-mapping>
tomcat初始化一个context的时候就会初始化context下面所有的 servlet,包括这个默认的servlet。
如图:
图待添加
它就是从servletContext里面加载的资源中去取出需要的资源,然后加载进来,并且判断相应的mime类型设置不同的HTTP head,然后输出到页面上。内容还是挺简单的。
其中还有mime的mapping:
- <mime-mapping>
- <extension>abs</extension>
- <mime-type>audio/x-mpeg</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>ai</extension>
- <mime-type>application/postscript</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>aif</extension>
- <mime-type>audio/x-aiff</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>aifc</extension>
- <mime-type>audio/x-aiff</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>aiff</extension>
- <mime-type>audio/x-aiff</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>aim</extension>
- <mime-type>application/x-aim</mime-type>
- </mime-mapping>
- <mime-mapping>
- <extension>art</extension>
- <mime-type>image/x-jg</mime-type>
- </mime-mapping>……后面太多贴不出来了