时间:2023-07-15 05:42:01 | 来源:网站运营
时间:2023-07-15 05:42:01 来源:网站运营
学习Tomcat(四)之Engine和Host容器:在前面的文章中,我们介绍了Tomcat的连接器Connector,连接器会监听指定的端口,并把接受到的消息转为HttpServletRequest和HttpServletResponse,交个Servlet容器处理。Tomcat的Servlet容器分为四种:Engin容器/Host容器/Context容器/Wrapper容器,这四个容器之间是父子关系,Engine容器包含Host容器,Host容器包含Context,Context包含Wrapper容器。本文会介绍Tomcat容器中的Engin容器和Host容器,在下一篇文章中会介绍Context容器和Wrapper容器。invoke(Request request,Response response)
。 <Engine name="Catalina" defaultHost="localhost"> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- 默认 Valve --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" <!-- maxDays="5" --> pattern="%h %l %u %t "%r" %s %b" /> <!-- 自定义 valve --> <Valve className="org.apache.catalina.valves.WswAccessValve"/> </Host> </Engine>
invoke(Request request,Response response)
,但是作用和Piple中的阀门不同,主要用于将请求传递到下一个容器或者对应的Servlet组件。StandardEngineValve
,这个Valve会读取Request中的Host信息,然后把请求路由给对应的Host容器。final class StandardEngineValve extends ValveBase { public StandardEngineValve() { super(true); } @Override public final void invoke(Request request, Response response) throws IOException, ServletException { // Ignore some code here. // Select the Host to be used for this Request Host host = request.getHost(); // Ignore some code here. // Ask this Host to process this request host.getPipeline().getFirst().invoke(request, response); }}
<Host name="www.ramki.com" appbase="ramki_webapps" /><Host name="www.krishnan.com" appbase="krishnan_webapps" /> <Host name="www.blog.ramki.com" appbase="blog_webapps" />
GET /appA/servletA/some-url HTTP/1.1 Host: www.ramki.com Proxy-Connection: keep-alive User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11 Accept: text/html,application/xhtml+xml,application/xml;q=0.9Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8
本文最先发布至微信公众号,版权所有,禁止转载!
关键词:容器,学习