码迷,mamicode.com
首页 > 编程语言 > 详细

html5 java多图片上传

时间:2015-07-06 11:36:03      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

<form enctype="multipart/form-data" action="url"  method="post">
  <input type="file" name="pic" />
  <input type="file" name="pic" />
  <input type="file" name="pic" />
  <input type="submit" value="提交"/>
</form>


private
List<String> uploadImgs(HttpServletRequest req,String name) throws Exception{ List<String> list = new ArrayList<String>(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) req; // 获得文件: List<MultipartFile> files = multipartRequest.getFiles(name); for(MultipartFile file:files){ String fileExtName = file.getOriginalFilename().substring(file.getOriginalFilename().indexOf(".") + 1); String realPath = req.getSession().getServletContext().getRealPath(""); String uuid = UUID.randomUUID().toString(); //String fileName = DateTimeUtil.getDateTime2Str3S4() + "." + fileExtName; String fileName = uuid + "." + fileExtName; String imgPath = "upload"+File.separatorChar+"appShootme" + File.separatorChar + fileName; String imgPathRealPath = realPath + File.separatorChar+ "upload"+File.separatorChar+"appShootme" + File.separatorChar + fileName; File fi = new File(imgPathRealPath); if (!fi.exists()) { fi.mkdirs(); } file.transferTo(fi); list.add(imgPath); } return list; }

 

html5 java多图片上传

标签:

原文地址:http://www.cnblogs.com/liyangxj/p/4623610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!