《深入分析Java Web技术内幕》读后感(servlet)

 

见书第九章 P243

在Tomcat的容器等级中,Context容器直接管理Servlet在容器中的包装类Wrapper,所以Context容器如何运行将直接影响Servlet的工作方式。

Servlet容器的启动过程

Tomcat的addWebapp方法:

public Context addWebapp(Host host, String url, String name, String path) {
        silence(host, url);

        Context ctx = new StandardContext();
        ctx.setName(name);
        ctx.setPath(url);
        ctx.setDocBase(path);

        ctx.addLifecycleListener(new DefaultWebXmlListener());
        ctx.setConfigFile(getWebappConfigFile(path, url));

        ContextConfig ctxCfg = new ContextConfig();
        ctx.addLifecycleListener(ctxCfg);
        
        // prevent it from looking ( if it finds one - it'll have dup error )
        ctxCfg.setDefaultWebXml(noDefaultWebXmlPath());

        if (host == null) {
            getHost().addChild(ctx);
        } else {
            host.addChild(ctx);
        }

        return ctx;
    }

Web应用的初始化工作

 

创建servlet实例

 1、创建servlet

 

 

2、初始化Servlet

Servlet体系结构

 

 

Servlet如何工作

 

 

Servlet中的listener

 

Filter如何工作

 

 

 

Servlet中的url-pattern

 

 

posted on 2017-11-24 16:04  Michael2397  阅读(306)  评论(0编辑  收藏  举报

导航