ITeye博客

spring3.0多文件上传

sharron5 · 2010-10-26 15:59 · 文件上传 · 企业架构 · Spring · MVC · Markdown

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]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。