---
title: "用spring mvc上传文件"
author: "xiajava2011"
date: "2011-11-28T09:29:25Z"
tags: []
categories: ["开源软件"]
slug: "spring-mvc"
draft: false
lastmod: "2011-11-28T09:32:05Z"
id: 1279652
url: "https://xiajava2011.iteye.com/blog/1279652"
---

```
后台：
```

```
    @RequestMapping
    public void addEpibolyPool(@RequestParam("fileName") CommonsMultipartFile file,TEpibolyPool epibolyPool,HttpServletResponse response) {
        logger.debug("EpibolyController add start...........");
        System.out.println("开始上传文件啦。。。。。。。");
        //上传文件
        String fileName = null;
        try {
            InputStream in = file.getInputStream();
            String uploadDir = "E:/";
            File dirPath = new File(uploadDir);
            if (!dirPath.exists()) {
                dirPath.mkdirs();
            }
            fileName = uploadDir+file.getOriginalFilename();
            File uploadedFile = new File(fileName);
            byte[] bytes = file.getBytes();
            FileCopyUtils.copy(bytes, uploadedFile);
            System.out.println("********************************上传成功");
        } catch (IOException e) {
            e.printStackTrace();
        }

        epibolyPool.setPersonnelStatus("16");//初始状态
        epibolyPool.setResideProvider(providerId);
        epibolyPool.setCreateTime(new Date());
        epibolyPool.setResumeLink(fileName);
        String pk = epibolyService.save(epibolyPool);
        logger.debug("EpibolyController add end........");
    }
```

 前台jsp:

```
<form action="../rest/epiboly/add" id="form1" method="post" enctype="multipart/form-data">
    <input type="file" value="" class="text" name="fileName" style="width:120px"/>
</form>
```