tomcat&jetty虚拟路径配置

  • tomcat
    1. 在tomcat解压目录的conf->Catalina->localhost文件夹下新建一个xml文件。path名称需和文件一致内容为
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/resource" docBase="F:\document\resource" 
  reloadable="true" />
</xml>
    2.  或者直接修改server.xml文件,在Host标签中添加
<Context path="/resource" docBase="F:\document\resource" 
  reloadable="true" />
  • jetty
    1. 在jetty解压目录的webapps文件下新建一个xml文件,内容为:
<?xml version="1.0"  encoding="UTF-8"?>  
<!DOCTYPE Configure PUBLIC   
    "-//Mort Bay Consulting//DTD Configure//EN"   
    "http://www.eclipse.org/jetty/configure_9_0.dtd">  

<Configure class="org.eclipse.jetty.server.handler.ContextHandler">  
    <Set name="contextPath">/resources</Set>  
    <Set name="handler">  
    <New class="org.eclipse.jetty.server.handler.ResourceHandler">  
    <Set name="resourceBase">F:\document\resource</Set>  
    <Set name="directoriesListed">true</Set>  
    </New>  
    </Set>  
</Configure>

将该xml重命名为resource.xml,contextPath的名称是什么就命名成什么.启动jetty之后,就可以通过 http://localhost:8080/resource 来访问 F:\document\resource 中的资源文件了。
  2. 或者在jetty.xml中加入如下代码:

<Set name="handler">
  <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
    <Set name="handlers">
     <Array type="org.eclipse.jetty.server.Handler">
       <Item>
         <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
         <Set name="contextPath">/resource</Set>  
       </Item>
       <Item>
         <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
         <Set name="resourceBase">F:\document\resource</Set>  
         <Set name="directoriesListed">true</Set>  
       </Item>
     </Array>
    </Set>
  </New>
</Set>

jetty相关配置未在本地测试,不保证完全正确。
以上所有方法均推荐第一种。

参考文章
http://blog.csdn.net/le_59/article/details/51774809
http://goinglw.iteye.com/blog/454187

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值