plupload,一个挺不错js框架。到时其官方demo中只是提供了php服务端代码。
下面是我个人修改的,通过Struts实现多文件上传。
package net.bingosoft.attach.action;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.bingosoft.attach.common.FileHelper;
import net.bingosoft.attach.service.AttachService;
import net.bingosoft.common.config.Config;
import net.bingosoft.common.struts.BaseAction;
import net.bingosoft.competition.model.VieFile;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class PluploadAction extends BaseAction{
static private final String RESP_SUCCESS = "{\"jsonrpc\" : \"2.0\", \"result\" : null, \"id\" : \"id\"}";
static private final String RESP_ERROR = "{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 101, \"message\": \"Failed to open input stream.\"}, \"id\" : \"id\"}";
static private final String JSON = "application/json";
private AttachService attachService;
public void uploadFile(HttpServletRequest request, HttpServletResponse response) throws IOException{
request.setCharacterEncoding("UTF-8");
String responseString = RESP_SUCCESS;
String belongId = request.getParameter("belongId");
String belongModel = request.getParameter("belongModel");
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
ServletFileUpload upload = new ServletFileUpload();
//webroot绝对路径
String webRootPath = FileHelper.getServerWebRoot();
String context = request.getContextPath();
try {
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
// Handle a multi-part MIME encoded file.
if (!item.isFormField()) {
String filename = item.getName();
InputStream input = item.openStream();
String filePath = FileHelper.getServerREFile(filename);
FileHelper.uploadFile(input, webRootPath+filePath);
if(belongModel.equals(Config.getString("JINGZHENG_UPLOAD_FLAG"))){
VieFile vieFile = new VieFile();
vieFile.setFid(UUID.randomUUID().toString());
vieFile.setIid(belongId);
vieFile.setFilePath(context+"/"+filePath);
vieFile.setFileName(filename);
attachService.getBaseDao().save(vieFile);
}
}
}
}
catch (Exception e) {
responseString = RESP_ERROR;
e.printStackTrace();
}
}
// Not a multi-part MIME request.
else {
responseString = RESP_ERROR;
}
response.setContentType(JSON);
byte[] responseBytes = responseString.getBytes();
response.setContentLength(responseBytes.length);
ServletOutputStream output = response.getOutputStream();
output.write(responseBytes);
output.flush();
}
public AttachService getAttachService() {
return attachService;
}
public void setAttachService(AttachService attachService) {
this.attachService = attachService;
}
}
分享到:
相关推荐
实现多文件上传,jsp java代码非常全,可直接运行,放心下载
Plupload是jquery文件上传插件,基于Struts2,亲测通过,放心使用!
springboot2、plupload2.3.6整合,实现文件批量上传、断点续传、秒传,带进度条,idea、maven工程
plupload php plupload 多文件上传组件
Plupload 上传.net MVC 上传示例
使用plupload实现多文件上传,单文件直接下载/多个文件打包下载 页面使用jquery easyui,后台使用commons包实现,包含oracle数据库建表sql
plupload 支持多文件上传、 后台servlet上传,大部分关键内容都在了!
NULL 博文链接:https://coconut-zhang.iteye.com/blog/1910234
plupload是一个支持多个文件上传并记录上传进度的组建,支持flash,html等
长话短说,采用spring springMVC mybatis maven mysql,实现多文件上传功能,下载使用的是流的形式。 其中涉及的分页我会另开一片博客介绍。 三、准备材料 plupload artDialog 还有一份初始化插件的js文件 ...
java+plupload多附件上传 servelet多附件上传
前端组件 plupload 文件上传demo
在struts2中用plupload实现多文件上传,取自别人,亲测可用
java使用plupload进行文件的拖拽,全选,文件夹等的批量上传操作,还可以对文件格式大小进行筛选,配置简单
Plupload 是一个Web浏览器上的界面友好的文件上传模块,可显示上传进度、图像自动缩略和上传分块。可同时上传多个文件。
plupload和java后台实现多图上传并把缩略图跟上传的url显示到画面上 1、使用jQuery的plupload实现上传功能,前台无需太多配置,简单修改即可符合您的要求。虽然是jQuery虽然是plupload,但是大多需要手动修改的地方...
代码里有plupload上传和uploadify上传两种可供大家参考,建议大家使用plupload上传,此上传各大种浏览器都兼容。uploadify上传和form验证同时使用的话,在FF和chrome浏览器下会存在cookie丢失的问题。
多文件上传JQUERY PLUPLOAD
使用plupload整合spring boot框架实现大文件断点续传功能,简单的使用了plupload API,最便捷实现断点续传功能。