HTML页面:

<html>
<body>
<form action="http://localhost:8080/项目名/controller/方法名" method="POST" enctype="multipart/form-data">
    yourfile: <input type="file" name="myfile"/><br/>
    <input type="submit" value="aaa"/>
</form>
</body>
</html>

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

Controller方法:

    @RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
    @ResponseBody
    public String fileUpload(HttpServletRequest request, HttpServletResponse response,
            @RequestParam MultipartFile myfile) throws IOException {
        // 用来检测程序运行时间
        long startTime = System.currentTimeMillis();
        try {          
            logger.info("文件长度: " + myfile.getSize());
            logger.info("文件类型: " + myfile.getContentType());
            logger.info("文件名称: " + myfile.getName());
            logger.info("文件原名: " + myfile.getOriginalFilename());
            logger.info("========================================");
            String realPath="E:\\test\\"+fwbs+"\\"+year+"\\"+month+"\\";
            FileUtils.copyInputStreamToFile(myfile.getInputStream(), new File(""E:\\test\\, “xxx.zip”));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("上传的运行时间:" + String.valueOf(endTime - startTime) + "ms");
        return msg;
    }

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄