zoukankan      html  css  js  c++  java
  • springMVC文件上传与下载

    
    
    /**
    *文件上传
    */
     1 @RequestMapping(value = { "download" })
     2 @ResponseBody
     3     public void download(
     4             HttpServletResponse response, HttpServletRequest request) throws IOException {
     5         String path=request.getServletContext().getRealPath("/")+"WEB-INF/download/erep/";
     6         String fileName="模板.xls";
     7         File file1=new File(path,fileName);
     8         response.setCharacterEncoding("UTF-8");
     9         //response.setContentType("application/x-msdownload");
    10         //response.setContentType("application/octet-stream; charset=utf-8");
    11         response.setHeader("Content-Disposition", "attachment; filename="+new String(fileName.getBytes("gbk"),"iso-8859-1"));
    12         response.setHeader("Content-Length", String.valueOf(file1.length()));
    13         ServletOutputStream out = response.getOutputStream();
    14         byte[] array = FileUtils.readFileToByteArray(file1);
    15         out.write(array);
    16         out.flush();
    17         out.close();
    18         
    19         
    20     }
         /**
          *文件上传
          */
         @RequestMapping(value = { "upload" }) @ResponseBody public void upload(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException { String name = file.getOriginalFilename(); String filename=UUID.randomUUID().toString()+name; String path=request.getServletContext().getRealPath("/")+"WEB-INF/download/erep/"; FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path+filename)); }

      

  • 相关阅读:
    连接APB1和APB2的设备有哪些
    STM32串口配置步骤
    gcc -o test test.c编译报错
    EmBitz1.11中将左边的目录弄出来
    c51
    c51跑马灯
    51 单片机 跑马灯2
    51 单片机 跑马灯
    spring注解注入:<context:component-scan>以及其中的context:include-filter>和 <context:exclude-filter>的是干什么的?
    Cookie和Session的作用和工作原理
  • 原文地址:https://www.cnblogs.com/mxggx/p/13608144.html
Copyright © 2011-2022 走看看