首页>代码>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();
        }
    }
}
 最近下载更多
最近下载更多
                
                qwe71656099     LV3
                10月13日
            
            
        
                stonewan     LV10
                7月29日
            
            
        
                krispeng     LV15
                6月4日
            
            
        
                genyuan2014     LV6
                2024年5月7日
            
            
        
                微信网友_6512020493586432     LV2
                2024年4月7日
            
            
        
                jiayongchao258     LV9
                2024年3月27日
            
            
        
                nyb4613     LV8
                2024年3月5日
            
            
        
                WBelong     LV8
                2023年12月26日
            
            
        
                ssh123     LV10
                2023年9月28日
            
            
        
                13165798872     LV11
                2023年9月7日
            
            
        
 
                 
                 最近浏览
最近浏览