µ±Ç°Î»ÖÃ: > Linux·þÎñÆ÷ > Tomcat >

Tomcatѧϰ֮Context

ʱ¼ä:2014-12-30 13:19À´Ô´:linux.it.net.cn ×÷Õß:IT

context

Ò»¸öcontext´ú±íÒ»¸öwebÓ¦Óã¬ËüÔËÐÐÔÚÌض¨µÄÐéÄâÖ÷»úÖУ¬Ã¿¸öwebÓ¦ÓÃҪôÊÇÒ»¸öwarÎļþ£¬ÒªÃ´ÊÇÒ»¸ö·ûºÏ¹æ·¶µÄĿ¼¡£Ò»°ãHTTPÇëÇ󷾶ÖдøÓÐrequestURI,ÎÒÃÇ¿ÉÒÔ´ÓrequestURIÖлñÈ¡ÉÏÏÂÎÄ·¾¶£¬¸ù¾ÝÉÏÏÂÎÄ·¾¶¿ÉÒÔÑ¡ÔñÊʺϵÄwebÓ¦ÓóÌÐòÀ´´¦ÀíÕâ¸öÇëÇó¡£Ä㻹¿ÉÒÔ¶¨Òå¶à¸öcontext,µ«Ã¿¸öcontextµÄÃû³Æ±ØÐëΨһ¡£

contextÒ»°ã»á³öÏÖÔÚÒÔÏÂÈý¸öµØ·½£º
(1)¡¢·Åµ½webÓ¦ÓõÄ/META-INF/context.xmlÖУ¬´ËʱÈç¹ûcopyXMLÊôÐÔΪtrue,»á½«Æä±»¿½±´µ½ $CATALINA_BASE/conf/[enginename]/[hostname]/ Ŀ¼ÖУ¬²¢ÃüÃûΪӦÓÃÃû£»
(2)¡¢Ö±½Ó·Åµ½$CATALINA_BASE/conf/[enginename]/[hostname]/ Ŀ¼Ï£¬¸ÃÎļþ½«×ÜÊÇÓÅÏÈÓÚ/META-INF/context.xml²¿Êð£»
(3)¡¢server.xmlÎļþµÄHostÔªËØÏÂÃæ

²¢²»ÍƼö½«contextÖ±½ÓдÔÚserver.xmlÎļþÖУ¬ÒòΪÐÞ¸Äserver.xmlÎļþ²»»áµ¼ÖÂÖØв¿Ê𣬱ØÐëÖØÐÂÆô¶¯tomcat²Å»áÉúЧ£¬µ«ÊÇÔÚserver.xmlÎļþÖпÉÒÔ¶¨Òå¶à¸öcontextÔªËØ£¬ÆäËûÁ½ÖÖÇé¿ö²»ÔÊÐí¡£´ËÍ⣬$CATALINA_BASE/conf/context.xmlÕâ¸öÎļþ»á±»ËùÓÐwebÓ¦ÓüÓÔØ£¬$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default»á±»Í¬Ò»Ì¨Ö÷»úµÄËùÓÐwebÓ¦ÓüÓÔØ¡£

StandardContext

standardContextÊÇContextµÄ±ê׼ʵÏÖ£¬ÏÂÃæÀ´¿´¿´Õâ¸öÀàÔÚ³õʼ»¯ºÍÆô¶¯µÄʱºò¶¼×öÁËЩʲôÊ¡£

initInternal

tomcatÔÚÆô¶¯µÄ¹ý³ÌÖÐÊÇÔõô´Óhost¹ý¶Éµ½contextµÄ£¿¼ÇµÃÔÚhostconfigÀàÖÐÔÚ²¿ÊðwebÓ¦ÓõÄʱºò»áµ÷ÓÃhost.addChild()·½·¨½«context¹ÒÔÚhostÃûÏÂ×÷ΪËüµÄ×ÓÈÝÆ÷

´ÓÉÏͼ¿ÉÒÔ¿´³öÔÚµ÷ÓÃhost.addChild()·½·¨Ê±´¥·¢ÁËchildµÄstart·½·¨£¬ÔÙÉúÃüÖÜÆÚÑ­»·µ½contextµÄinitInternal·½·¨

¿´¿´Õâ¸ö·½·¨µÄ´úÂ룺

 

[java] view plaincopyprint?
 
  1. protected void initInternal() throws LifecycleException {  
  2.     super.initInternal();  
  3.       
  4.     if (processTlds) {  
  5.         this.addLifecycleListener(new TldConfig());  
  6.     }  
  7.   
  8.     // Register the naming resources  
  9.     if (namingResources != null) {  
  10.         namingResources.init();  
  11.     }  
  12.   
  13.     // Send j2ee.object.created notification   
  14.     if (this.getObjectName() != null) {  
  15.         Notification notification = new Notification("j2ee.object.created",  
  16.                 this.getObjectName(), sequenceNumber.getAndIncrement());  
  17.         broadcaster.sendNotification(notification);  
  18.     }  
  19. }  
ºÜ¼òµ¥×öÁËÁ½¼þÊ£º1¡¢Ìí¼Ótld±êÇ©ÅäÖÃÎļþ¼àÌýÆ÷£»2¡¢·¢ËͶÔÏó´´½¨µÄÏûÏ¢£¬ÕâÉæ¼°µ½JMXµÄ֪ʶ£¬ÐèÒªÕÒ¸öʱ¼äרÃÅÑо¿¡£

 

startInternal

±ÈinitInternal·½·¨¸´Ôӵö࣬´óÌåÉÏ×öÁËÒÔϼ¸¼þÊ£º

1¡¢¹¹½¨webappclassLoader; 

2¡¢´ÓCharsetMapperDefault.propertiesÖлñÈ¡×Ö·û¼¯£¬Ä¬ÈÏÖ»Ö§³ÖÁ½ÖÖen=ISO-8859-1ºÍfr=ISO-8859-1

3¡¢´´½¨¹¤³ÌĿ¼workdir=work/enginename/hostname/contextname

4¡¢contextÆô¶¯Íêºó£¬Ëæ¼´Æô¶¯ËüµÄ¸½Êô×é¼þ£ºloader,logger,pipeline,sessionManagerµÈ

5¡¢´¥·¢contextconfig.lifecycleEventµ÷ÓÃcontextConfig.lifecycleEvent´¦Àíweb.xmlÅäÖÃÎļþ

5¡¢Æô¶¯ËüµÄÿ¸öwrapper×ÓÈÝÆ÷

6¡¢¼ÓÔغͳõʼʼ»¯ÄÇЩ±êʶ"load on startup"µÄservletÀà

 

ÅäÖÃ

contextÔªËØÅäÖÃÏîÏ൱¶à£¬Ìô¼¸¸öÖØÒªµÄ˵˵£º
className£ºcontextµÄʵÏÖÀ࣬ĬÈÏΪStartardcontext
cookies£ºÊÇ·ñÆôÓÃcookies£¬Ä¬ÈÏΪtrue
docBase£ºwebÓ¦ÓÃËùÔÚµÄĿ¼£¬µ±context¶¨ÒåÔÚserver.xmlʱÕâ¸öÖµ±ØÐëÉèÖ㬵±docbase²»ÔÚwebappsĿ¼ÏÂʱҲ±ØÐëÉèÖÃ
path£ºwebÓ¦ÓõÄÉÏÏÂÎÄ·¾¶£¬Í¬Ò»Ì¨Ö÷»ú±ØÐëΨһ£¬Èç¹ûΪ¿Õ´®Ôò¿ÉÒÔ´¦ÀíËùÓÐÇëÇó
unpackWAR£ºStandard ContextÖÐÌØÓеÄÊôÐÔ£¬Èç¹ûΪfalse±íʾwar°ü²»»á±»½âѹ£¬Ä¬ÈÏΪtrue
workDir£ºStandard ContextÖÐÌØÓеÄÊôÐÔ£¬JSPµÈ»á±»±àÒëÔÚÕâ¸öĿ¼

reloadable£ºÈç¹ûÄãÐèÒª¼àÊÓ /WEB-INF/classes/ ºÍ/WEB-INF/libĿ¼ÏµÄÎļþ£¬¾Í°ÑËüÉèÖÃΪtrue°É£¬±ä»¯ºó»áÖØÔØwebÓ¦Ó㬿ª·¢µÄʱºòºÜÓÐÓã¬Ä¬ÈÏΪfalse£¬³£³£Ìáµ½µÄÖØв¿ÊðºÍÖØмÓÔØ£¬Á½ÕßÖ®¼äµÄÇø±ðºóÐøÔÙ·ÖÎö¡£

(ÔðÈα༭£ºIT)
------·Ö¸ôÏß----------------------------
À¸Ä¿Áбí
ÍƼöÄÚÈÝ