作者:mobiledu2502863483 | 来源:互联网 | 2023-10-13 06:07
【0】README0.1)本文主要以图片的形式分析他们大致的调用过程;0.2)0.3)应用程序的sourcecode如下:publicfinalclassBootstra
【0】README
0.0)本文中源代码的背景,参见 tomcat(9)session管理
0.1)本文主要以图片的形式分析他们大致的调用过程;
0.2)HttpCOnnector== org.apache.catalina.connector.http.HttpConnector; 而StandardCOntext== org.apache.catalina.core.StandardContext;
0.3)应用程序的source code 如下:
public final class Bootstrap {
public static void main(String[] args) {
System.setProperty("catalina.base", System.getProperty("user.dir"));
Connector cOnnector= new HttpConnector();
Wrapper wrapper1 = new SimpleWrapper();
wrapper1.setName("Session");
wrapper1.setServletClass("SessionServlet");
Context cOntext= new StandardContext();
context.setPath("/myApp");
context.setDocBase("myApp");
context.addChild(wrapper1);
context.addServletMapping("/myApp/Session", "Session");
LifecycleListener listener = new SimpleContextConfig();
((Lifecycle) context).addLifecycleListener(listener);
Loader loader = new WebappLoader();
context.setLoader(loader);
connector.setContainer(context);
Manager manager = new StandardManager();
context.setManager(manager);
try {
connector.initialize(); // highlight line.
((Lifecycle) connector).start(); // highlight line.
((Lifecycle) context).start(); // highlight line.
// make the application wait until we press a key.
System.in.read();
((Lifecycle) context).stop();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
【1】HttpConnector.initialize()
【2】HttpConnector.start()
【3】StandardContext.start()
/**
* Load and initialize all servlets marked "load on startup" in the
* web application deployment descriptor.
*
* @param children Array of wrappers for all currently defined
* servlets (including those not declared load on startup)
*/
public void loadOnStartup(Container children[]) { // org.apache.catalina.core.StandardContext.loadOnStartUp().
// Collect "load on startup" servlets that need to be initialized
TreeMap map = new TreeMap();
for (int i = 0; i
tomcat(supplement)HttpConnector.initialize() 和 start() 方法 以及 StandardContext.start()方法的分析