目录
1.前端
function downloadFile() {
let pictureSourceServer = "http://192.168.1.1:8080/downFile/";
let fileName = "测试文档.xlsx";
let fileURL = pictureSourceServer + fileName;
// 创建一个隐藏的链接元素
let link = document.createElement("a");
link.href = fileURL;
link.download = fileName; // 设置下载时文件名
document.body.appendChild(link);
// 模拟点击链接,触发文件下载
link.click();
// 下载后移除链接
document.body.removeChild(link);
}
2.Tomcat服务器内配置
web.xml的最下边
<Context docBase="E:\tomcat\downFile" path="/downFile" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
3.在Tomcat映射的文件内放置文件

4.重启Tomcat,下载测试
