最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
SpringMVC多个文件上传及上传后立即显示图片功能
时间:2022-06-29 01:16:26 编辑:袖梨 来源:一聚教程网
多文件上传就是改良一个方法把MultipartFile类换成CommonsMultipartFile类,因为上传多个文件用数组方式的话MultipartFile类不能初始化,它不支持数组
package com.meng.upload;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
@Controller
public class upload {
@RequestMapping(value="/upload",method=RequestMethod.POST)
public String upload(@RequestParam("file1") CommonsMultipartFile[] file1, HttpServletRequest request) {
for (CommonsMultipartFile commonsMultipartFile : file1) {
try {
File file = new File(request.getServletContext().getRealPath("upload"),
System.currentTimeMillis() + "_"
+ commonsMultipartFile.getOriginalFilename());
System.out.println(file.getPath()+"");
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(commonsMultipartFile.getBytes());
fileOutputStream.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return "ok";
}
}
index.jsp页面上传立即显示图片
My JSP 'index.jsp' starting page
相关文章
- 差差漫画登录首页-差差漫画在线登录免费弹窗 02-06
- 抖音网页版入口-官方电脑版登录免费教程2026 02-06
- 差差漫画官方最新版本下载安装入口-差差漫画免费高清漫画页面在线观看 02-06
- 百度地图如何打开全景模式-百度地图全景开启方法 02-06
- poki游戏官网正版入口-poki游戏正版安全无忧官网 02-06
- picacg游咔-官网最新入口2026 02-06