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 虛擬目錄了。html
Tomcat6設置虛擬目錄的方法, 不修改server.xml java
在tomcat文件夾的conf"catalina"localhost(對於Tomcat6版本及其以上,須要本身建立catalina和localhost這兩個文件夾) web
增長project .xml文件(該文件名的project要和下面的「path=「/xxx"」的xxx相同)瀏覽器
文件內容: tomcat
<Context path="/project" reloadable="true" docBase="E:"javastudio"oob" workDir="E:"javastudio"oob"work" />app
docBase是項目文件夾的web-inf文件夾的上一層目錄
workDir是指Tomcat解析Jsp轉換爲Java文件,並編譯爲class存放的文件夾,設置在項目文件夾裏面,能夠避免移植到其餘地方首次讀取jsp文件須要從新解析 。通常格式:項目文件夾"work
reloadable是指能夠從新加載,通常設置爲true,方便使用,不須要常常重啓Tomcat。
less
之後啓動Tomcat,在瀏覽器輸入http://localhost:8080/project就能訪問
該項目的welcome文件。webapp
轉: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,嘗試了一些方法:jsp
-----------------------------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.ide
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便可。