Tomcat6.0
    
    
      虛擬目錄配置
    
    
      [
    
    
      轉(zhuǎn)
    
    
      ] 
      
    
    
      設(shè)虛擬目錄
    
    
       "site"
    
    
      ,通過
    
    
      
        http://localhost:8080/site
      
    
    
      訪問物理路徑
    
    
       D:"site 
    
    
      文件夾里面的內(nèi)容。設(shè)置過程如下:
    
    
      
      1.
    
    
      復(fù)制
    
    
       Tomcat6.0"webapps"ROOT 
    
    
      目錄下的
    
    
       WEB-INF 
    
    
      文件夾到
    
    
       D:"site 
    
    
      目錄下。
    
    
      
      2.
    
    
      打開
    
    
       D:"site"WEB-INF 
    
    
      目錄下的
    
    
       web.xml 
    
    
      文件
    
    
      ,
    
    
      在
    
    
       </description> 
    
    
      之后加入:
    
    
      
      <!--JSPC servlet mappings start --> 
      
      <!--JSPC servlet mappings end --> 
      
      3.
    
    
      打開
    
    
       Tomcat6.0"conf"server.xml 
    
    
      文件,在
    
    
       <Host> 
    
    
      和
    
    
       </Host> 
    
    
      之間加入:
    
    
      
      <Context path="/site" docBase="d:"site"></Context> 
      
      path="/site" 
    
    
      就是虛擬目錄的名稱
    
    
      
      docBase="d:"site"> 
    
    
      為物理路徑
    
    
      
      4.
    
    
      打開
    
    
       Tomcat6.0"conf"web.xml 
    
    
      文件,找到
    
    
      : 
      
      <init-param> 
      
      <param-name>listings</param-name> 
      
      <param-value>false</param-value> 
      
      </init-param> 
      
    
    
      把
    
    
      false
    
    
      設(shè)成
    
    
      true
    
    
      保存,重啟
    
    
      Tomcat
    
    
      ,現(xiàn)在就可以應(yīng)用
    
    
      
        http://localhost:8080/site
      
    
    
      虛擬目錄了。
    
    
    
  
Tomcat6 設(shè)置虛擬目錄的方法 , 不修改 server.xml
    
      
    
    
      在
    
    
      tomcat
    
    
      文件夾的
    
    
      conf"catalina"localhost(
    
    
      對于
    
    
      Tomcat6
    
    
      版本及其以上,需要自己創(chuàng)建
    
    
      catalina
    
    
      和
    
    
      localhost
    
    
      這兩個文件夾
    
    
      ) 
    
  
增加 project .xml 文件(該文件名的 project 要和下面的 “path=“/xxx"” 的 xxx 相同)
文件內(nèi)容 :
<Context path="/project" reloadable="true" docBase="E:"javastudio"oob" workDir="E:"javastudio"oob"work" />
    
      
      docBase
    
    
      是項(xiàng)目文件夾的
    
    
      web-inf
    
    
      文件夾的上一層目錄
    
    
      
      workDir
    
    
      是指
    
    
      Tomcat
    
    
      解析
    
    
      Jsp
    
    
      轉(zhuǎn)換為
    
    
      Java
    
    
      文件,并編譯為
    
    
      class
    
    
      存放的文件夾,設(shè)置在項(xiàng)目文件夾里面,可以避免移植到其他地方首次讀取
    
    
      jsp
    
    
      文件需要重新解析
    
    
      。一般格式:項(xiàng)目文件夾
    
    
      "work 
      
      reloadable
    
    
      是指可以重新加載,一般設(shè)置為
    
    
      true
    
    
      ,方便使用,不需要經(jīng)常重啟
    
    
      Tomcat
    
    
      。
    
    
      
      ?
    
  
    
      以后啟動
    
    
      Tomcat
    
    
      ,在瀏覽器輸入
    
    
      
        http://localhost:8080/project
      
    
    
      就能訪問
    
    
      
    
    
      該項(xiàng)目的
    
    
      welcome
    
    
      文件。
    
  
轉(zhuǎn): TomCat 6.0 虛擬目錄配置! 2008 年 03 月 09 日 星期日 13:51 之前在 5.0 下配置虛擬目錄,我一般是采用在 conf"server.xml 中增加 <Context .../> 的方法,可是此法在 6.0 中失效 ( 后經(jīng)驗(yàn)證有效,可能是之前實(shí)驗(yàn)過程中有誤 ) 。按照 tomcat 6.0 啟動之后的相關(guān)文檔的說明 http://localhost:8080/docs/config/context.html ,嘗試了一些方法:
    
      -----------------------------tomcat6.0
    
    
      文檔中關(guān)于
    
    
      Context
    
    
      的說明
    
    
      -------------------
      
      You may define as many Context elements as you wish. Each such Context MUST have a unique context path. In addition, a Context must be present with a context path equal to a zero-length string. This Context becomes the default web application for this virtual host, and is used to process all requests that do not match any other Context's context path.
    
  
For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifing the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat.
    
      
      Context elements may be explicitly defined:
    
  
    
      in the $CATALINA_HOME/conf/context.xml file: the Context element information will be loaded by all webapps 
      
      in the $CATALINA_HOME/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host 
      
      in individual files (with a ".xml" extension) in the $CATALINA_HOME/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml) extension will be used as the context path. Multi-level context paths may be defined using #, e.g. context#path.xml. The default web application may be defined by using a file called ROOT.xml. 
      
      if the previous file was not found for this application, in an individual file at /META-INF/context.xml inside the application files 
      
      inside a Host element in the main conf/server.xml 
      
      -------------------------------------------------------------------------------
    
  
逐一驗(yàn)證,方法 1 , 2 均無效,成功的有以下 2 種: ( 下文用 %tomcat% 表示 Tomcat6.0 的安裝目錄,希望在瀏覽器中通過 http://localhost:8080/abc/default.jsp 來訪問 d:"myJsp"default.jsp)
方法一: ( 文檔中說不建議使用 )
    
      找到
    
    
      %tomcat%"conf"server.xml
    
    
      ,在
    
    
      </Host>
    
    
      之前加入:
    
    
      
      <Context docBase="d:"myJsp" path="/abc" />
      
    
    
      保存文件之后,重啟
    
    
      Tomcat
    
    
      即可。注意:大小寫不能錯
    
    
      ! 
    
    
      斜桿
    
    
      "/"
    
    
      或
    
    
      """
    
    
      的方向別搞錯。
    
  
方法二:該方法推薦使用,比較簡單。
    
      在
    
    
      %tomcat%"conf"Catalina"locahost(
    
    
      該目錄可能需要手工創(chuàng)建
    
    
      )
    
    
      下新建一個文件
    
    
      abc.xml
    
    
      ,注意文件名中的
    
    
      abc
    
    
      就表示虛擬目錄的名稱,所以不可隨意命名,該文件的內(nèi)容為
    
    
      : 
      
      <Context docBase="d:"myJsp" />
      
    
    
      重啟
    
    
      Tomcat
    
    
      即可。
    
  
    
      -------------------------------------------------------------------------------------------
      
    
    
      其它設(shè)置:當(dāng)
    
    
      url
    
    
      中未明確指定文件名時,是否列出相關(guān)目錄下所有文件的開關(guān)設(shè)置:
    
  
    
      打開
    
    
       %tomcat%"conf"web.xml 
    
    
      文件,找到
    
    
      : 
      
      <init-param> 
      
      <param-name>listings</param-name> 
      
      <param-value>false</param-value> 
      
      </init-param> 
      
    
    
      把
    
    
      false
    
    
      改成
    
    
      true
    
    
      即可。
    
  
    
      -------------------------------------------------------------------------------------------
      
    
    
      其他人的同類經(jīng)驗(yàn):
    
    
      
        http://fengzhiyu-sh.javaeye.com/blog/153506
      
    
    
      經(jīng)驗(yàn)證無需設(shè)置文中的
    
    
      web application
    
    
      下的
    
    
      web.xml
    
    
      文件。
    
    
      
      ?
    
  
?
?
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
 
					微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
 
					

