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的项目,并 ...
随机推荐
- 关于命令行参数argv(《学习OpenCV》)
在<学习OpenCV>这本书中,很多示例代码都用到了命令行参数.作为新手,之前总是很困扰,不知道怎么用.偶然的机会终于略知一二了. 在Visual Studio中,我们可以自行设置命令行参 ...
- 【week2】燃尽图
燃尽图(burn down chart)是在项目完成之前,对需要完成的工作的一种可视化表示.燃尽图有一个Y轴(工作)和X轴(时间).理想情况下,该图表是一个向下的曲线,随着剩余工作的完成,“烧尽”至零 ...
- 使用getRequestDispatcher跳转后 能获取到request.setAttribute数据 分析
- javascript中面向对象的5种写法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- NOIP2018初赛 游记
这玩意写个鬼游记啊 听说普及+提高的考两张卷子€€£也是想得出来 怎么监考还能咕咕咕的啊 怎么我到快结束了才做完啊 怎么我根本不知道初赛能带啥啊 怎么dij我都能想着对的选了错的啊 怎么我根本不知道图 ...
- 前台界面(1)---HTML基本定义及常见标签
已经很久没有更新博客了,从今天开始要继续走在学习的路上,话不多说,先来干货: 目录 1. HTML定义 2. H标签 3. Img标签 4. P标签 5. A标签 6. 无序列表 7. 有序列表 8. ...
- 获取接口参数名带有“abc”的参数的值
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext) va ...
- 【倍增】LCM QUERY
给一个序列,每次给一个长度l,问长度为l的区间中lcm最小的. 题解:因为ai<60,所以以某个点为左端点的区间的lcm只有最多60种的情况,而且相同的lcm区间的连续的. 所以就想到一个n*6 ...
- POJ3468:A Simple Problem with Integers——题解
http://poj.org/problem?id=3468 实现一个线段树,能够做到区间修改和区间查询和. 明显板子题. #include<cstdio> #include<cma ...
- CodeForces.71A Way Too Long Words (水模拟)
CodeForces71A. Way Too Long Words (水模拟) 题意分析 题怎么说你怎么做 没有坑点 代码总览 #include <iostream> #include & ...