这几天学习了Web入门的相关知识,总结了些知识点,写出来给大家共享下~
2、Apache Tomcat的配置文件含义:
bin:存放启动和配置Tomcat的脚本文件
conf:存放Tomcat的配置文件
lib:存放Tomcat使用的支撑jar包
logs:存放Tomcat的日志文件
temps:存放Tomcat运行时产生的临时文件
webapps:存放WEB应用
work:Tomcat的工作目录
3、如何在Tomcat中配置Web应用的虚拟目录的映射
查看Tomcat Documentation,一共有5种方式配置:
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 the Context 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
.
第一种方式:在Tomcat的conf下context.xml中配置,该配置是适用于该Tomcat服务器下所有Web应用。
第二种方式:在$CATALINA_BASE/conf/[enginename]/[hostname]/context.xml下配置,该配置是适用于该主机下所有Web应用。
第三种方式:在$CATALINA_BASE/conf/[enginename]/[hostname]/下的单独一个XML中配置,这个XML的文件名就是Web应用的路径,如果XML文件名以#间隔,那么Web路径就会相应的用/间隔。
第四种方式:将打好的War包放入服务器WebAPPs中,服务器会自动生成访问的路径。
第五种方式:直接在conf/server.xml中,配置好后需要重启Tomcat。
配置格式:
<Context Path="/Helloworld" docBase="C:\Hello"/>
Path后面写入虚拟目录,那么通过 http://localhost:8080/Helloworld/xxx资源,就能访问Web应用的资源了
4、配置虚拟主机
在conf\server.xml下
<Host name="www.xxx.com" appBase="c:\Hello"
<Context Path="/Helloworld" docBase="C:\Hello"/>
浏览器访问www.xxx.com,会去DNS请求该域名的IP地址,找到主机后访问缺省的首页。
5、将Web应用打成War包命令,dos命令找到对应目录,如下图:
将War包放入Tomcat/WapApps,服务器会自动解压出来。