1、将工程打包,打成war包,点击右键,选择export
2、将xxxx.war包拷贝至${tomcat.home}\webapps目录下。
3、重启tomcat,tomcat启动时会自动将xxxx.war文件解包。
4、修改${tomcat.home}\conf\server.xml文件.在Host节点下增加<Context>节点,内容入下:
<Context path="/" docBase="xxxx" debug="0" reloadable="true" />
docBase:指向项目的根目录所在的路径,可以是绝对路径,也可以是相对${tomcat.home}\webapps的相对路径。
path:是一个虚拟目录,这里设置成了"userapp",则启动Tomcat后,你将通过http://localhost:8080/userapp/*.html来访问项目的相关页面.如果你要只输入ip地址就显示主页,则该键值留为空。
reloadable:如果设置为"true",则表示当你修改jsp文件后,不需要重启服务器就可以实现页面显示的同步.
举例:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="yanzel" debug="0" reloadable="true" />
</Host>
path必须为空字符串,yanzel为位于webapps目录下的应用,则收入http://localhost时,直接进入yanzel的默认页面。
5、重启tomcat
6、在浏览器中输入http://localhost:8080/login.html,访问网站页面。
7、此方式如果直接输入http://localhost:8080,还是会定位至tomcat7默认目录。
8、修改默认目录方法
修改$tomcat/conf/web.xml文件。
在web.xml文件中,有一段如下:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
在<welcome-file-list>与<welcome-file>index.html</welcome-file>之间添加上:<welcome-file>a.jsp</welcome-file>保存上述两个文件后重启tomcat,在浏览器地址栏内输入"http://localhost:8080/",显示a.jsp页面的内容。
如果网站WEB-INF下设置了web.xml,则网站的设置会覆盖conf下的web.xml设置。
附:war包发布项目的原理
1.因为所有新建的文件夹都在WebRoot文件夹下
2.所有的页面都在WebRoot文件夹下
3.所有的后台代码都编译成 .class文件,在WebRoot \ WEB-INF \ classes 下面
4.习惯将所有的 .jar包放在WebRoot \ WEB-INF \ lib 下面