如何设置tomcat的默认应用

通常我们访问我们的web应用格式为:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. http://127.0.0.1:8080/myApp  


但是想直接通过 输入 本地ip直接进入我们的应用该如何设置呢:如输入:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. http://127.0.0.1  

1,好 首先我们需要修改tomcat默认端口号:需要将tomcat的默认端口 8080 改为缺省的端口号 80

这是需要修改tomcat根目录下的conf目录下的  server.xml 文件

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <Connector port="8080" protocol="HTTP/1.1"  
  2.               connectionTimeout="20000"  
  3.               redirectPort="8443" />  


 

将上面的 port 修改为 80 即可,这样就省去每次测试都要带端口的麻烦了。

 

2,然后就是修改默认的webapp了。

同样是修改server.xml文件

在文件最后的Host标签中的value标签后面 加上 context标签 如下:

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <Host name="localhost"  appBase="webapps"  
  2.            unpackWARs="true" autoDeploy="true">  
  3.   
  4.        <!-- SingleSignOn valve, share authentication between web applications  
  5.             Documentation at: /docs/config/valve.html -->  
  6.        <!-- 
  7.        <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> 
  8.        -->  
  9.   
  10.        <!-- Access log processes all example.  
  11.             Documentation at: /docs/config/valve.html  
  12.             Note: The pattern used is equivalent to using pattern="common" -->  
  13.        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
  14.               prefix="localhost_access_log." suffix=".txt"  
  15.               pattern="%h %l %u %t "%r" %s %b" />  
  16.     <Context path="" docBase="D:\apache\apache-tomcat-7.0.26\webapps\OnlineExam">  
  17.             <WatchedResource>WEB-INF/web.xml</WatchedResource>  
  18.     </Context>  
  19.   
  20.   
  21.      </Host>  


上面Context标签 部分为新添加的部分 只要将 docBase中的路径修改为 你的应用的路径即可。然后重启tomcat 输入ip就可直接访问你的缺省应用了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值