多文件上传就是改良一个方法把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
原神祈愿模拟器最新版
原神祈愿模拟器手机版是一款完整汉化的趣味原神抽卡模拟小游戏,
宝宝森林美食完整版
宝宝森林美食游戏最新版是一款十分有趣的休闲益智游戏,帮助宝宝
g沙盒仇恨官方英文版(gorebox)
G沙盒仇恨英文原版是一款最近非常火热的沙盒模拟类游戏,在这里
迷你世界测试服最新版2024
迷你世界测试服2021最新版,即迷你世界的先遣服版本,用户能
闪耀暖暖最新版2024
闪耀暖暖手游这是非常好玩的换装手游,游戏内容丰富有趣,游戏环