java springmvc4 图片或文件上传
1、文件配置
配置文件解析

上传文件处理的核心方法
// uploadOneFile.jsp, uploadMultiFile.jsp submit to.
@RequestMapping(value = "/doUpload", method = RequestMethod.POST)
public String uploadFileHandler(HttpServletRequest request, Model model,
@RequestParam("file") MultipartFile[] files) { // Root Directory.
String uploadRootPath = request.getServletContext().getRealPath(
"upload");
System.out.println("uploadRootPath=" + uploadRootPath); File uploadRootDir = new File(uploadRootPath); // Create directory if it not exists.
if (!uploadRootDir.exists()) {
uploadRootDir.mkdirs();
}
// 创建
List<File> uploadedFiles = new ArrayList<File>();
for (int i = 0; i < files.length; i++) {
MultipartFile file = files[i]; // Client File Name
String name = file.getOriginalFilename();
System.out.println("Client File Name = " + name); if (name != null && name.length() > 0) {
try {
byte[] bytes = file.getBytes(); // Create the file on server
File serverFile = new File(uploadRootDir.getAbsolutePath()
+ File.separator + name); // Stream to write data to file in server.
BufferedOutputStream stream = new BufferedOutputStream(
new FileOutputStream(serverFile));
stream.write(bytes);
stream.close(); uploadedFiles.add(serverFile);
System.out.println("Write file: " + serverFile);
} catch (Exception e) {
System.out.println("Error Write file: " + name);
}
}
}
model.addAttribute("uploadedFiles", uploadedFiles);
return "uploadResult";
}
也可参见一个很不错的api连接:
https://www.yiibai.com/spring_mvc/spring-mvc-file-upload-tutorial.html
java springmvc4 图片或文件上传的更多相关文章
- JAVA Web 之 struts2文件上传下载演示(二)(转)
JAVA Web 之 struts2文件上传下载演示(二) 一.文件上传演示 详细查看本人的另一篇博客 http://titanseason.iteye.com/blog/1489397 二.文件下载 ...
- JAVA Web 之 struts2文件上传下载演示(一)(转)
JAVA Web 之 struts2文件上传下载演示(一) 一.文件上传演示 1.需要的jar包 大多数的jar包都是struts里面的,大家把jar包直接复制到WebContent/WEB-INF/ ...
- Java 利用SWFUpload多文件上传 session 为空失效,不能验证的问题 swfUpload多文件上传
Java 利用SWFUpload多文件上传 session 为空失效,不能验证的问题(转) 我们都知道普通的文件上传是通过表单进行文件上传的,还不能达到异步上传的目的.通过使用某些技术手段,比如jqu ...
- selenium+java利用AutoIT实现文件上传
转自https://www.cnblogs.com/yunman/p/7112882.html?utm_source=itdadao&utm_medium=referral 1.AutoIT介 ...
- java常见3种文件上传速度对比和文件上传方法详细代码
在java里面文件上传的方式很多,最简单的依然是FileInputStream.FileOutputStream了,在这里我列举3种常见的文件上传方法代码,并比较他们的上传速度(由于代码是在本地测试, ...
- vue+Ueditor集成 [前后端分离项目][图片、文件上传][富文本编辑]
后端DEMO:https://github.com/coderliguoqing/UeditorSpringboot 前端DEMO:https://github.com/coderliguoqing/ ...
- UEditor独立图片、文件上传模块
百度的UEditor编辑器的强大之处不用多说,但是有时候我们只想用他的文件.图片上传模块,不想把这个编辑器加载出来,话不多说,直接上实现代码: 引用文件: <script src="~ ...
- AFNetworking之多图片-文件上传
在分享经验之前,先说点题外话,之前的一个项目涉及到了多图片的上传,本来以为是一个很简单的事情,却着实困扰了我好久,究其原因,一是我不够细心,二是与后台人员的交流不够充分.在此,我想将我的老师常说的一句 ...
- 在 .NET Core项目中使用UEditor图片、文件上传服务
在.NET Framework中使用UEditor时,只需要将UEditor提供的后端服务,部署为一个子程序,即可直接使用文件上传相关的服务,但是UEditor官方并未提供.Net Core的项目,并 ...
随机推荐
- iOS AVAudioPlayer播放音频时声音太小
iOS AVAudioPlayer播放音频时声音太小 //引入AVFoundation类库,设置播放模式就可以了 do { try AVAudioSession.sharedInstance().ov ...
- C#,Winform 文件的导入导出 File
1.导入 导入对话框:OpenFileDialog private void sbtnsb_Click(object sender, EventArgs e) { try { OpenFileDial ...
- 【Docker 教程】- Docker 架构
1.Docker 使用客户端-服务器 (C/S) 架构模式,使用远程API来管理和创建Docker容器. 2.Docker 容器通过 Docker 镜像来创建. 3.容器与镜像的关系类似于面向对象编程 ...
- c++移动文件夹
bool Files::MoveSampleFolder(string src_path,string dst_path) { int index = src_path.find_last_of(&q ...
- 再看RCU
从昨天晚上开始,我就立志要把RCU拿下,昨晚加今天早上看了RCU的东西,太细节的原理我就不扣了,放弃,知道RCU是怎么用的就可以了,赶紧看文件系统中dcache的管理了. 说说RCU,RCU其实是很简 ...
- RT-thread内核之消息队列
一.消息队列控制块:在include/rtdef.h中 #ifdef RT_USING_MESSAGEQUEUE /** * message queue structure */ struct rt_ ...
- 在@Async注解下RequestContextHolder.getRequestAttributes() 获得null的情况
我们有的时候会在service层获取request填充一些诸如用户名和IP地址等信息,这个时候如果不想从Controller层传request,可以在service直接使用 HttpServletRe ...
- 【题解】HNOI2004敲砖块
题目传送门:洛谷1437 决定要养成随手记录做过的题目的好习惯呀- 这道题目乍看起来和数字三角形有一点像,但是仔细分析就会发现,因为选定一个数所需要的条件和另一个数所需要的条件会有重复的部分,所以状态 ...
- Json对象转为实体对象
Json对象转为实体对象 1.Bean中申明 trainTypeList: public class TrainTypeQueryParam implements Serializable { pri ...
- bzoj 4725 [POI2017]Reprezentacje ró?nicowe 暴力
[POI2017]Reprezentacje ró?nicowe Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 141 Solved: 67[Sub ...