tomcat服务器设置文件下载

设置Tomcat的虚拟目录
{tomcat_home}/conf/server.xml

 <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="examples" reloadable="true" crossContext="true">  
      Context>  
        
        

        
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
          Host>

增加以下代码,c://download为你存放文件的路径,/download,为你在浏览器要访问的路径

<Context docBase="C://download" path="/download" reloadable="true" />  

结果

<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="examples" reloadable="true" crossContext="true">  
      Context>  
      <Context docBase="C://download" path="/download" reloadable="true" />  
        
        

        
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
          Host>

如果需要文件夹可被访问,配置web.xml,修改配置如下

 <servlet>  
    <servlet-name>default</servlet-name>  
    <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>  
    <init-param>  
        <param-name>debug</param-name>  
        <param-value>0</param-value>  
    </init-param>  
    <init-param>  
        <param-name>listings</param-name>  
        <param-value>false</param-value>  
    </init-param>  
    <load-on-startup>1</load-on-startup>  
</servlet>  

注意:上面的false改为true

ok,这就好了,访问就可以了
tomcat服务器设置文件下载_第1张图片

你可能感兴趣的:(服务器)