Tomcat 6.0下虚拟目录的成功配置

之前在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.iteye.com/blog/153506 经验证无需设置文中的web application下的web.xml文件。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值