1. 目录结构:
在tomcat的安装目录下有个webapps文件夹,在此文件夹下创建如下:
项目名文件夹,如hello:
WEB-----》对于web是不可见文件夹
classes: 放Java类
lib: 放依赖的库
web.xml :
网页文件直接放到项目文件夹hello下,如建立index.html 和hello.html
web.xml 文件中,直接copy下面的内容进去就可以:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
</web-app>
直接http://ipAddress:port/hello/hello.html或直接http://ipAddress:port/hello将直接访问hello文件夹下的index.html
2. 建虚拟路径
编辑tomcat目录下的server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/world" docBase="D:\Test_html\hello" reloadable="true"/> -----》这是新加入的
path:虚拟路径, 以后就可以直接打开网址http://localhost:8888/world/
docBase: 项目文件夹路径
reloadable: 网页修改后是否自动重载
3. 修改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>
表示当路径后面不加额外的html文件名时,自动加载index命名的网页,若找不到则返回404。也可以收动加入其他自动加载的文件<welcome-file>fiileName</welcome-file>
开发过程中,可以更改listings 设置为true,若找不到welcome-file文件时则会把项目文件夹下的目录显示出来(WEB-INF不会显示),开发结束必须重新设置为false。
<param-name>listings</param-name>
<param-value>false</param-value>