tomcat配置静态资源访问

在开发中,如果项目的一些静态资源,如用户上传的文件等, 不是放在项目路径.而是放在磁盘的其他地方的,那么是不能直接通过url进行访问的. 就需要在tomcat的server.xml 中配置 Context节点.

docBase为映射的磁盘路径

 path为访问路径的上下文. 如 ip:port/apiDownload/123.img. 即可访问到该静态资源

reloadable: 默认值为false. 当为"true"时, 会监视WEB-INF/classes和WEB-INF/lib目录下class文件的改动,如果监测到有class文件更新,服务器会自动重新加载Web应用. 在正式环境中这种设置会加重服务器的负载. 一般正式环境中使用false

  <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">


		  <Context path="/apiDownload" docBase="D:\Wing\Uploads\" reloadable="false"/>
       
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

猜你喜欢

转载自blog.csdn.net/qq_40085888/article/details/88371259