servlet工作原理

  1. Servelt容器例如Tomcat、Jetty等

  2. Tomcat容器模型
    分为4个等级,一个Context对应一个Web,Context配置举例:

<Context path="/simple01" docBase="/data/www/simple01"
 reloadable="true" />

Tomcat container model

  1. 启动过程
 Tomcat tomcat = getTomcatInstance();
 File appDir = new File(getBuildDirectory(), "webapps/examples");
 tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
 tomcat.start();
 ByteChunk res = getUrl("http://localhost:" + getPort() +
               "/examples/servlets/servlet/HelloWorldExample");
 assertTrue(res.toString().indexOf("<h1>Hello World!</h1>") > 0);
  1. Servlet结构