---
title: "spring3.0多文件上传"
author: "sharron5"
date: "2010-10-26T15:59:48Z"
tags: ["MVC", "Spring"]
categories: ["企业架构"]
slug: "spring3-0"
draft: false
lastmod: "2010-10-26T15:59:48Z"
id: 794566
url: "https://sharron5.iteye.com/blog/794566"
---

spring配置：\[code="java"] \[/code] controller: \[code="java"]/\** * 文件上传 * @param request * @param response * @return * @throws Exception \*/ @RequestMapping(value="/uploadFile",method=RequestMethod.POST) public ModelAndView uploadFile(MultipartHttpServletRequest request) throws Exception{ PropertiesUtil pUtil=PropertiesUtil.createPropertiesUtil(Constant.UPLOADPATH\_FILE); List files=request.getFiles("file"); String uploadpath=request.getSession().getServletContext().getRealPath(pUtil.getProperty(Constant.UPLOADPATH\_PATH)); System.out.println("uploadpath :"+uploadpath); for (MultipartFile file : files) { if (file.isEmpty()) continue; FileOutputStream fileOS=new FileOutputStream(uploadpath+"/"+file.getOriginalFilename()); fileOS.write(file.getBytes()); fileOS.close(); } return new ModelAndView("/success"); } \[/code]