首页>代码>Spring MVC+Mybatis+Ehcache+Apache Shiro+Bootstrap整合开发java仓库管理系统源码>/WMS/src/main/java/com/ken/wms/common/controller/FileSourceHandler.java
package com.ken.wms.common.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; /** * 处理文件下载请求 * * @author Ken */ @Controller @RequestMapping("/commons/fileSource") public class FileSourceHandler { @RequestMapping(value = "download/{fileName:.+}", method = RequestMethod.GET) public void fileDownload(@PathVariable("fileName") String fileName, HttpServletRequest request, HttpServletResponse response) throws IOException { if (fileName == null) return; // 获取文件 ServletContext context = request.getServletContext(); String directory = context.getRealPath("/WEB-INF/download"); Path file = Paths.get(directory, fileName); if (Files.exists(file)) { // 设置响应头 response.addHeader("Content-Disposition", "attachment;filename=" + file.getFileName()); Files.copy(file, response.getOutputStream()); response.getOutputStream().flush(); } } }
最近下载更多
jiayongchao258 LV9
昨天
nyb4613 LV7
3月5日
WBelong LV6
2023年12月26日
ssh123 LV10
2023年9月28日
13165798872 LV11
2023年9月7日
weilaizhisheng LV21
2023年7月4日
karthurly LV3
2023年3月16日
无名氏111 LV32
2023年2月24日
Sun_YJ LV4
2023年2月5日
旧街小巷 LV2
2022年12月11日
最近浏览更多
jiayongchao258 LV9
昨天
uid0901 LV2
3月13日
yangyang567 LV1
3月8日
1437047954
3月7日
暂无贡献等级
zhang-lei
3月6日
暂无贡献等级
bollshit LV1
3月4日
1134116035
2月24日
暂无贡献等级
xxg634460601 LV3
2月22日
root111snkdnc LV3
1月19日
952773464
1月15日
暂无贡献等级