前提条件:
提前将静态资源文件建设好路径和文件夹内容,否则tomcat会如上图报错,启动失败
1、增加tomcat外部下载目录映射
在…\Apache Software Foundation\Tomcat 8.5\conf\server.xml文件下
```clike 标签内增加 ```开始配置
首先在 E:\Program Files\document 文件夹下放一个记事本文件 a.txt
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<!--doBase是静态资源路径位置, path作用相当于设置的key, doBase作用相当于value -->
<Context path="/download" docBase="E:\Program Files\document"></Context>
</Host>
2、在web.xml中 的
<servlet>
<init-param>
<param-name>listings</param-name>
<!--设置为true -->
<param-value>true</param-value><!--此处的false改为true-->
</init-param>
</servlet>
3.前端页面下载文件夹内的资源访问方法
<p><a style="color:#1e9fff " href="https://localhost/download/a.txt">下载记事本文件</a>”下载模板</p>
其中download 相当于后台的接口
@RequestMapping("/download")
@ResponseBody
就是去tomcat服务器中寻找这个key(key = E:\Program Files\document)
然后找下边的资源文件