使用tomcat_2——虚拟目录映射
2016-07-11 12:04
429 查看
参看:http://www.cnblogs.com/xdp-gacl/p/3734395.html
Tomcat服务器虚拟目录的映射方式
第一种:让tomcat服务器自动映射(推荐)
tomcat服务器会自动管理webapps目录下的所有web应用,并把它映射成虚似目录。换句话说,tomcat服务器webapps目录中的web应用,外界可以直接访问。
第二种:添加自己的xml
参考Tomcat服务器文档:
In individual files (with a ".xml" extension) in the
extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
意思就是:在tomcat服务器的\conf\Catalina\localhost目录下添加一个以xml作为扩展名的文件,xml文件的名字可以任意取,比如下面的aa.xml,注意这一句话"The context path and version will be derived from the base name of the file",这一句话的意思翻译过来就是"context元素的path属性源自于是这个xml文件的名字",上面提到过,Context元素的path属性是用来配置虚似目录的名称的,所以虚似目录的名称就是这个xml文件的名称。
在aa.xml文件中添加Context元素映射JavaWeb应用,代码如下:
这里的docBase就是源目录,也就是实际存放web应用的目录。类似于tomcat的webapp目录。
这里需要特别注意的是:aa.xml虽然可以任意命名,但是一旦名字确定后,外部访问时的url就要相应做调整,比如:http://localhost:8080/aa/
第三种:修改service.xml的host元素
找到server.xml文件的host元素,例如在<Host></Host>这对标签加上<Contextpath="/JavaWebApp"
docBase="F:\JavaWebDemoProject"/>即可将在F盘下的JavaWebDemoProject这个JavaWeb应用映射到JavaWebApp这个虚拟目录上,JavaWebApp这个虚拟目录是由Tomcat服务器管理的,JavaWebApp是一个硬盘上不存在的目录,是我们自己随便写的一个目录,也就是虚拟的一个目录,所以称之为"虚拟目录"。
其中,Context表示上下文,代表的就是一个JavaWeb应用,Context元素有两个属性,
Ⅰ.path:用来配置虚似目录,必须以"/"开头。
Ⅱ.docBase:配置此虚似目录对应着硬盘上的Web应用所在目录。
注意:path部分可以随便命名,但是和上一种情况一样,注意URL与path名相关。
注意:在Tomcat6之后中,不再建议在server.xml文件中使用配置context元素的方式来添加虚拟目录的映射,因为每次修改server.xml文件后,Tomcat服务器就必须要重新启动后才能重新加载server.xml文件。在Tomcat服务器的文档http://localhost:8080/docs/config/context.html中有这样的说明:
It is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifying theContext configuration more invasive since the main
Individual Context elements may be explicitly defined:
In an individual file at
file name plus a ".xml" extension.
In individual files (with a ".xml" extension) in the
always take precedence over any context.xml file packaged in the web application's META-INF directory.
Inside a
Host element in the main
Tomcat服务器虚拟目录的映射方式
第一种:让tomcat服务器自动映射(推荐)
tomcat服务器会自动管理webapps目录下的所有web应用,并把它映射成虚似目录。换句话说,tomcat服务器webapps目录中的web应用,外界可以直接访问。
第二种:添加自己的xml
参考Tomcat服务器文档:
In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/directory. The context path and version will be derived from the base name of the file (the file name less the .xml
extension). This file will always take precedence over any context.xml file packaged in the web application's META-INF directory.
意思就是:在tomcat服务器的\conf\Catalina\localhost目录下添加一个以xml作为扩展名的文件,xml文件的名字可以任意取,比如下面的aa.xml,注意这一句话"The context path and version will be derived from the base name of the file",这一句话的意思翻译过来就是"context元素的path属性源自于是这个xml文件的名字",上面提到过,Context元素的path属性是用来配置虚似目录的名称的,所以虚似目录的名称就是这个xml文件的名称。
$CATALINA_BASE指的就是tomcat服务器根目录,
[enginename]指的是Tomcat服务器使用的引擎名称,Tomcat使用的引擎是Catalina
在aa.xml文件中添加Context元素映射JavaWeb应用,代码如下:
1 <Context docBase="F:\JavaWebDemoProject" />
这里的docBase就是源目录,也就是实际存放web应用的目录。类似于tomcat的webapp目录。
这里需要特别注意的是:aa.xml虽然可以任意命名,但是一旦名字确定后,外部访问时的url就要相应做调整,比如:http://localhost:8080/aa/
第三种:修改service.xml的host元素
找到server.xml文件的host元素,例如在<Host></Host>这对标签加上<Contextpath="/JavaWebApp"
docBase="F:\JavaWebDemoProject"/>即可将在F盘下的JavaWebDemoProject这个JavaWeb应用映射到JavaWebApp这个虚拟目录上,JavaWebApp这个虚拟目录是由Tomcat服务器管理的,JavaWebApp是一个硬盘上不存在的目录,是我们自己随便写的一个目录,也就是虚拟的一个目录,所以称之为"虚拟目录"。
其中,Context表示上下文,代表的就是一个JavaWeb应用,Context元素有两个属性,
Ⅰ.path:用来配置虚似目录,必须以"/"开头。
Ⅱ.docBase:配置此虚似目录对应着硬盘上的Web应用所在目录。
注意:path部分可以随便命名,但是和上一种情况一样,注意URL与path名相关。
注意:在Tomcat6之后中,不再建议在server.xml文件中使用配置context元素的方式来添加虚拟目录的映射,因为每次修改server.xml文件后,Tomcat服务器就必须要重新启动后才能重新加载server.xml文件。在Tomcat服务器的文档http://localhost:8080/docs/config/context.html中有这样的说明:
It is NOT recommended to place <Context> elements directly in the server.xml file. This is because it makes modifying theContext configuration more invasive since the main
conf/server.xmlfile cannot be reloaded without restarting Tomcat.
Individual Context elements may be explicitly defined:
In an individual file at
/META-INF/context.xmlinside the application files. Optionally (based on the Host's copyXML attribute) this may be copied to
$CATALINA_BASE/conf/[enginename]/[hostname]/and renamed to application's base
file name plus a ".xml" extension.
In individual files (with a ".xml" extension) in the
$CATALINA_BASE/conf/[enginename]/[hostname]/directory. The context path and version will be derived from the base name of the file (the file name less the .xml extension). This file will
always take precedence over any context.xml file packaged in the web application's META-INF directory.
Inside a
Host element in the main
conf/server.xml.
相关文章推荐
- eclipse项目配置tomcat后浏览器访问不到项目解决方案
- Tomcat 配置 默认应用 (去掉项目名称、移除项目名称)
- Nginx转发给Tomcat页面去掉端口号
- 部署terracotta集群存储tomcat的session
- tomcat 404 问题及解决方法
- 性能测试中用LambdaProbe监控Tomcat
- eclipse远程调试Tomcat方法(测试成功并且说说遇到的坑)
- Tomcat 指定的服务已存在 Failed installing 'Tomcat8'
- Cronolog 分割 Tomcat8 Catalina.out日志
- Server Tomcat v7.0 Server at localhost failed to start.怎么处理
- 如何解决 Apache Tomcat 目录遍历漏洞
- tomcat如何路由映射网址
- tomcat如何路由映射网址
- Linux 给新用户授予、设置Tomcat目录的使用权限
- [WebServer] Tomcat 配置访问限制:访问白名单和访问黑名单
- 一台机子上运行使用不同Java版本的多个tomcat
- 如何配置和使用Tomcat访问日志
- tomcat简介之web.xml详解(转)
- netbeans启动tomcat失败
- eclipse中启动tomcat的项目路径