//注:$CATALINA_BASE表示Tomcat安装的目录,后面你会看到
//前半部分为分析,后半部分为实战
//CATALINA -->一个好听的名字:卡特琳娜
什么是web应用的部署和网站目录的映射?说白了就是如何让用户访问到我们开发的网站。
众所周知我么做好的网站都是放在某台服务器的某个硬盘的某个文件里面,
比如我开发了一个网站,将其放在了XXX服务器的E:\MyWeb文件夹下面
现在我想让别人访问到我的网站,该如何做呢?
在Tomcat 6.0.36的帮助文档里给出了详细的说明,
装好Tomcat后打开以下地址你就可以看到该文档了
http://localhost:8080/docs/config/context.html
//关于如何部署web应用和映射网站目录,Tomcat原文如下
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 modifying theContext configuration more invasive since the mainconf/server.xml
file cannot be reloaded without restarting Tomcat.
Context elements may be explicitly defined:
- In the
$CATALINA_BASE/conf/context.xml
file: the Context element information will be loaded by all webapps. - In the
$CATALINA_BASE/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_BASE/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.foo#bar.xml
for a context path of/foo/bar
. The default web application may be defined by using a file calledROOT.xml
. - Only if a context file does not exist for the application in the
$CATALINA_BASE/conf/[enginename]/[hostname]/
, in an individual file at/META-INF/context.xml
inside the application files. If the web application is packaged as a WAR then/META-INF/context.xml
will be copied to$CATALINA_BASE/conf/[enginename]/[hostname]/
and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer/META-INF/context.xml
is placed in the host's appBase. - Inside a Host element in the main
conf/server.xml
.
With the exception of server.xml, files that define Context elements may only define a singleContext element.
//由以上可知Tomcat给了5种方法让我们配置web应用,这里我讲的是第三种,
//简单实用,无需重启Tomcat
//原文翻译如下
//在扩展名为.xml的档案文件,说的就是xml文件啦
In individual files (with a ".xml" extension)
//在Tomcat安装目录下的localhost文件夹
//如我的为 D:\Tomcat\Tomcat6.0.36\conf\Catalina\localhost
in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.
//文件名除去.xml后缀,将被用作web应用的路径
//何为context path? 比如我在localhost文件为ok.xml 则ok就是context path了
//用户打开网页的形式为http://XXX:8080/ok/123.html
//注:ok.xml里配有123.html的路径,如<context docBase="E:\Web"/>
//E:\Web里放着123.html
The name of the file (less the .xml extension) will be used as the context path.
//多级路劲用#号来定义,此时文件名形式为aaa#bbb#ccc.xml
//访问形式为http://XXX:8080/aaa/bbb/ccc/123.html
Multi-level context paths may be defined using #,
e.g. foo#bar.xml for a context path of /foo/bar.
//定义默认的网页应用建立ROOT.xml文件即可
//别忘了在ROOT.xml里设置网站的路径
The default web application may be defined by using a file called ROOT.xml.
//实战部分
1)我测试的网页放在E:\MyWeb下,截图如下
2)Tomcat安装在D:\Tomcat\Tomcat6.0.36 截图如下
3)进入localhost目录D:\Tomcat\Tomcat6.0.36\conf\Catalina\localhost
//在localhost目录下建立文件ok.xml 内容为<Context docBase="E:\MyWeb"/>
//截图如下
4)启动Tomcat,访问http://localhost:8080/ok/hello.html 即可
///附-->一种简单的访问web应用的方法
//将我们的web应用的整个目录拷贝到Tomcat安装目录下的webapps文件夹即可
//如将MyWeb拷贝到webapps
// 然后启动Tomcat 访问http://localhost:8080/MyWeb/hello.html即可
REFS:http://blog.csdn.net/friendan/article/details/8116743