tomcat6版本虛擬目錄詳細配置

來源:互聯網
上載者:User

在tomcat6版本中:

一、
1、【官方文檔】本人不推薦。
在tomcat\conf下server.xml中找到
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
</Host>
在其中添加:
<Context path="" docBase="換成你的路徑" reloadable="true"></Context>
這的docBase要改成你的項目目錄。
2、 不修改server.xml【推薦使用此方法】
在tomcat檔案夾的conf"catalina"localhost(對於Tomcat6版本及其以上,需要自己建立catalina和localhost這兩個檔案夾)下建立一個xml檔案。內容為
<?xml version="1.0" encoding="UTF-8"?>
<Context
    docBase="換成你的路徑"
    reloadable="true">
</Context>
檔案名稱改成你自己的譬如http://localhost:8080/bbs ,檔案名稱就為bbs.xml

其他配置:
開啟 Tomcat6.0"conf"web.xml 檔案,找到:
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
把false設成true儲存,重啟Tomcat,讓tomcat6支援檔案清單顯示

二、

Tomcat6.0虛擬目錄配置[轉]
設虛擬目錄 "site",通過 http://localhost:8080/site 訪問實體路徑 D:"site 檔案夾裡面的內容。設定過程如下:
1.複製 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設成true儲存,重啟Tomcat,現在就可以應用 http://localhost:8080/site 虛擬目錄了。

Tomcat6設定虛擬目錄的方法, 不修改server.xml


在tomcat檔案夾的conf"catalina"localhost(對於Tomcat6版本及其以上,需要自己建立catalina和localhost這兩個檔案夾)

增加project .xml檔案(該檔案名稱的project要和下面的“path=“/xxx"”的xxx相同)

檔案內容:

<Context path="/project" reloadable="true" docBase="E:"javastudio"oob" workDir="E:"javastudio"oob"work" />


docBase是專案檔夾的web-inf檔案夾的上一層目錄
workDir是指Tomcat解析Jsp轉換為Java檔案,並編譯為class存放的檔案夾,設定在專案檔夾裡面,可以避免移植到其他地方首次讀取jsp檔案需要重新解析 。一般格式:專案檔夾"work
reloadable是指可以重新載入,一般設定為true,方便使用,不需要經常重啟Tomcat。
 

以後啟動Tomcat,在瀏覽器輸入http://localhost:8080/project就能訪問
該項目的welcome檔案。

轉:TomCat 6.0虛擬目錄配置。2008年03月09日 星期日 13:51之前在5.0下配置虛擬目錄,我一般是採用在conf"server.xml中增加<Context .../>的方法,可是此法在6.0中失效(後經驗證有效,可能是之前實驗過程中有誤)。按照tomcat 6.0啟動之後的相關文檔的說明http://localhost:8080/docs/config/context.html,嘗試了一些方法:

-----------------------------tomcat6.0文檔中關於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
-------------------------------------------------------------------------------

逐一驗證,方法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(該目錄可能需要手工建立)下建立一個檔案abc.xml,注意檔案名稱中的abc就表示虛擬目錄的名稱,所以不可隨意命名,該檔案的內容為:
<Context docBase="d:"myJsp" />
重啟Tomcat即可。

-------------------------------------------------------------------------------------------
其它設定:當url中未明確指定檔案名稱時,是否列出相關目錄下所有檔案的開關設定:

開啟 %tomcat%"conf"web.xml 檔案,找到:
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
把false改成true即可。

-------------------------------------------------------------------------------------------
其他人的同類經驗:http://fengzhiyu-sh.javaeye.com/blog/153506 經驗證無需設定文中的web application下的web.xml檔案。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.