一、需要下载一个tomcat,这里演示采用tomcat8。
二、打开tomcat-1.8\webapps:
新建example文件,在example下新建test.html,添加如下内容:
<!DOCTYPE HTML><html lang="en"><head> <meta charset="UTF-8"> <title>Apache Tomcat Examples</title> </head> <body> <p> <h3>Apache Tomcat Examples</H3> <p></p> <ul> <li><a href="servlets">Servlets examples</a></li> <li><a href="jsp">JSP Examples</a></li> <li><a href="websocket/index.xhtml">WebSocket Examples</a></li> </ul> </body></html>
三、打开tomcat-1.8\conf下的server.xml文件:
找到如下标签<Host></Host>:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
修改成如下,添加了(<Context path="" docBase="example" reloadable="true"/>),docBase=刚刚新建的项目名example:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context path="" docBase="example" reloadable="true"/> </Host>
四、打开tomcat-1.8\conf下的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>
修改为,添加刚刚新建的test.html:
<welcome-file-list> <welcome-file>test.html</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
五、打开tomcat-1.8\bin,双击startup.bat启动tomcat:
在浏览器输入localhost:8080:
可以看到默认的页面变成了我们指定的页面