xheditor1.1.5 版本文件上传使用html5-application/octet-stream
Spring3 MVC之前写的上传程序无法支持
@RequestMapping(value = "/upload")
public String uploadFile(Model m, MultipartHttpServletRequest request) throws IOException {
String path = UploadController.class.getResource("/").getPath().split("WEB-INF")[0] + "upload/";
Iterator<String> iterator = request.getFileNames();
while (iterator.hasNext()) {
String next = iterator.next();
List<MultipartFile> files = request.getFiles(next);
for (int i = 0; i < files.size(); i++) {
if (!files.get(i).isEmpty()) {
byte[] bytes = files.get(i).getBytes();
String uploadFile = UploadUtils.generateFilename(path, UploadUtils.getExtension(files.get(i).getOriginalFilename(), "jpg"));
File file = new File(uploadFile);
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes);
fos.close();
m.addAttribute("url", uploadFile.replace(path, "/upload"));
m.addAttribute("local", uploadFile);
}
}
}
return "upload";
}
需要改造如下:
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String upload(Model m, HttpServletRequest request) throws IOException {
String path = UploadController.class.getResource("/").getPath().split("WEB-INF")[0] + "upload/";
if ("application/octet-stream".equals(request.getContentType())) { //HTML 5 上传
try {
String dispoString = request.getHeader("Content-Disposition");
int iFindStart = dispoString.indexOf("filename =\"") + 10;
int iFindEnd = dispoString.indexOf("\"", iFindStart);
String sFileName = dispoString.substring(iFindStart, iFindEnd);
int i = request.getContentLength();
byte buffer[] = new byte[i];
int j = 0;
while (j < i) { //获取表单的上传文件
int k = request.getInputStream().read(buffer, j, i - j);
j += k;
}
if (buffer.length >= 0) { //文件是否为空
String uploadFile = UploadUtils.generateFilename(path, UploadUtils.getExtension(sFileName, "jpg"));
File file = new File(uploadFile);
OutputStream out = new BufferedOutputStream(new FileOutputStream(file, true));
out.write(buffer);
out.close();
m.addAttribute("url", uploadFile.replace(path, "/upload"));
m.addAttribute("local", uploadFile);
}
} catch (Exception ex) {
m.addAttribute("err", ex.getMessage());
}
}
return "upload";
}
分享到:
相关推荐
xheditor-1.2.2.zip
xheditor-0.9.8-zh-cn.zip 编辑器xheditor-0.9.8-zh-cn.zip 编辑器xheditor-0.9.8-zh-cn.zip 编辑器xheditor-0.9.8-zh-cn.zip 编辑器xheditor-0.9.8-zh-cn.zip 编辑器
inflating: zuitu/static/js/xheditor/xheditor_emot/msn/3.gif inflating: zuitu/static/js/xheditor/xheditor_emot/msn/30.gif inflating: zuitu/static/js/xheditor/xheditor_emot/msn/31.gif inflating: ...
xheditor在asp.net中使用时,如果textbox控件在UpdatePanel使用...在本文件在包含完整的xheditor-1.1.13及其demos。在demos文件夹里的Default2.aspx及Default2.aspx.cs是解决textbox控件在UpdatePanel的正常使用方法。
xheditor编辑器.................xheditor编辑器.................xheditor编辑器.................xheditor编辑器.................xheditor编辑器.................
xheditor-1.1.7 编辑器插件 包含xheditor所含关键文件及jquery,导入web工程即可使用
最新版本xheditor-v1.2.2
文本编辑器文件包 具体介绍见博客 文本编辑器文件包
xheditor-1.1.6,html编辑器
一款很好用的编辑器,xheditor-1.2.1(demo,js,api,doc),官网上下载的最新代码,方便查阅参考
html5Upload:是否开启HTML5上传支持 参数值:true(允许),false(不允许),默认为true允许 说明:本功能需要浏览器支持HTML5上传 备注:1.0.0 Final新添加 upMultiple:允许一次上传多少个文件 参数值:大于0的数值,...
spring3MVC框架基本配置案例,里面两个功能案例,上传下载功能和使用xheditor发布消息功能
将下载的压缩文件解压缩,上传其中的xheditor-zh-cn.min.js以及xheditor_emot、xheditor_plugins和xheditor_skin三个文件夹到网站相应文件夹中。 注:如果您网站中没有使用jQuery框架,也请一并上传jquery文件夹中的...
这是一个富文本编辑器 使用起来很简单 几句代码就搞定了 当然也相对简单。
xheditor-1.2.1 上传图片 jquery版本:jquery-1.11.0 ASP.NET环境
xheditor-1.1.5 测试可用 感觉很行 就是比较简单,对网页要求不大,主要编辑网站的可以考虑哦
xhEditor是一个基于jQuery开发的简单迷你并且高效的可视化HTML编辑器,基于网络访问并且兼容IE 6.0+,Firefox 3.0+,Opera 9.6+,Chrome 1.0+,Safari 3.22+。
xhEditor编缉器,用于java开发时,上传文件,同时解决了在火狐上使用时报错的问题,主要是因为火狐上传时使用的是HTML5,如何解决请花1分吧!! 记得把xheditor里的上传改成servlet的路径呀!!
内置强大的Ajax上传,包括HTML4和HTML5上传支持(多文件上传、真实上传进度及文件拖放上传),追求完美的用户上传体验。 Word完美支持 实现Word代码自动检测并清理,提供高效完美的Word代码过滤方案,生成代码最优化...
xhEditor是一个基于jQuery开发的简单迷你并且高效的在线可视化HTML编辑器,基于网络访问并且兼容IE 6.0+,Firefox 3.0+,Opera 9.6+,Chrome 1.0+,Safari 3.22+。 xhEditor完全基于Javascript开发,您可以应用在任何的...