锁定老帖子 主题:tomcat架构分析(容器类)
精华帖 (1) :: 良好帖 (1) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2012-05-17
最后修改:2012-05-21
Tomcat提供了engine,host,context及wrapper四种容器。在总体结构中已经阐述了他们之间的包含关系。这四种容器继承了一个容器基类,因此可以定制化。当然,tomcat也提供了标准实现。
org.apache.catalina.core.ContainerBase
org.apache.catalina.core.StandardEngine
<Engine name="Catalina" defaultHost="localhost"> <Valve className="MyValve0"/> <Valve className="MyValve1"/> <Valve className="MyValve2"/> …… <Host name="localhost" appBase="webapps"> </Host> </Engine>
org.apache.catalina.core.StandardHost
org.apache.catalina.core.StandardContext
org.apache.catalina.session.StandardManager
<servlet> <servlet-name>httpserver</servlet-name> <servlet-class>com.gearever.servlet.TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>httpserver</servlet-name> <url-pattern>/*.do</url-pattern> </servlet-mapping>
request.getRequestDispatcher(url).forward(request, response)
public RequestDispatcher getRequestDispatcher(String path) { // Validate the path argument if (path == null) return (null); if (!path.startsWith("/")) throw new IllegalArgumentException (sm.getString ("applicationContext.requestDispatcher.iae", path)); // Get query string String queryString = null; int pos = path.indexOf('?'); if (pos >= 0) { queryString = path.substring(pos + 1); path = path.substring(0, pos); } path = normalize(path); if (path == null) return (null); pos = path.length(); // Use the thread local URI and mapping data DispatchData dd = dispatchData.get(); if (dd == null) { dd = new DispatchData(); dispatchData.set(dd); } MessageBytes uriMB = dd.uriMB; uriMB.recycle(); // Use the thread local mapping data MappingData mappingData = dd.mappingData; // Map the URI CharChunk uriCC = uriMB.getCharChunk(); try { uriCC.append(context.getPath(), 0, context.getPath().length()); /* * Ignore any trailing path params (separated by ';') for mapping * purposes */ int semicolon = path.indexOf(';'); if (pos >= 0 && semicolon > pos) { semicolon = -1; } uriCC.append(path, 0, semicolon > 0 ? semicolon : pos); context.getMapper().map(uriMB, mappingData); if (mappingData.wrapper == null) { return (null); } /* * Append any trailing path params (separated by ';') that were * ignored for mapping purposes, so that they're reflected in the * RequestDispatcher's requestURI */ if (semicolon > 0) { uriCC.append(path, semicolon, pos - semicolon); } } catch (Exception e) { // Should never happen log(sm.getString("applicationContext.mapping.error"), e); return (null); } Wrapper wrapper = (Wrapper) mappingData.wrapper; String wrapperPath = mappingData.wrapperPath.toString(); String pathInfo = mappingData.pathInfo.toString(); mappingData.recycle(); // Construct a RequestDispatcher to process this request return new ApplicationDispatcher (wrapper, uriCC.toString(), wrapperPath, pathInfo, queryString, null); }
org.apache.catalina.core.StandardWrapper
public class LoginServlet extends HttpServlet implements javax.servlet.SingleThreadModel{ …… }
org.apache.catalina.servlets.DefaultServlet
org.apache.jasper.servlet.JspServlet
<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>
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2012-05-18
刚看到,发贴时代码中的红色部分怎么标啊
|
|
返回顶楼 | |
发表时间:2012-05-18
期待楼主下文啊。。。
|
|
返回顶楼 | |
发表时间:2012-05-31
写的很好,学习了。工作之余,写点自己见解,楼主加油
|
|
返回顶楼 | |
发表时间:2013-04-09
gearever 写道 刚看到,发贴时代码中的红色部分怎么标啊
实在不行可以用贴图. 嘿嘿 |
|
返回顶楼 | |
浏览 4189 次