【javaWeb第四天】-Web资源访问概述

本文介绍了如何在Tomcat服务器中部署Web应用,包括通过放置在webapps文件夹、使用虚拟主机映射以及通过配置context.xml文件的方式。此外还讲解了如何设置应用的默认首页及配置热更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

netstat - ano查看端口占用情况


Web应用供外界访问方法
1.放在tomcat的webapp文件夹中。
2.虚拟映像
tomcat提供5种方法。
http://localhost:8080/docs/config/context.html

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 called ROOT.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 和Web应用不在同一个盘中,可在 tomcat的conf/Catalina/localhost目录中加一个XML文件,文件名为虚拟映像名,如zpy.xml,内容为<Context docBase="F:\web文件名"/>,服务器会自动加载该应用。


在项目的Web-inf目录中可配置首页,输入项目名即可访问(http://localhost:8080/Test/

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>





reloadable 设置为true.改过之后 不需要重新发布,服务器会自动 更新。在实际开发中最好不要配制,因为一但改动就会重新加载,应用较大时一旦连续加载会挂掉。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值