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便可。