在含有Struts2框架的应用中添加KindEditor上传图片功能
2012-09-15 15:51
465 查看
KindEditor是一个轻便的图文编辑器,有一批人在维护和更新,还有很多热心人在源源不断的提出问题和建议,值得一试。
这个东西使用起来非常的方便,KindEditor在源码的/jsp/目录下已经有写好的upload功能,稍作修改即可适应Struts2使用。
upload code:
被替换的代码:
还有就是KindEditor的FileManager功能,如果你要转移原jsp中的代码至Struts action时,需要注意KindEditor会传递一些Action中并不存在的一些键值,Struts会有对应的warn和exception;
由于FileManager只是对upload成功的文件做一些查询和预览的功能,建议是用servlet替代Struts Action 。
这个东西使用起来非常的方便,KindEditor在源码的/jsp/目录下已经有写好的upload功能,稍作修改即可适应Struts2使用。
upload code:
MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) this.getRequest(); String fileName = wrapper.getFileNames("imgFile")[0]; File file = wrapper.getFiles("imgFile")[0]; saveUrl += newFileName; FileOutputStream fos = new FileOutputStream(savePath + newFileName); byte[] buffer = new byte[1024]; InputStream in = new FileInputStream(file); try { int num = 0; while ((num = in.read(buffer)) > 0) { fos.write(buffer, 0, num); } } catch (Exception e) { e.printStackTrace(System.err); } finally { try{ if(in != null) in.close(); if(fos != null) fos.close(); }catch(IOException e){} } JSONObject obj = new JSONObject(); obj.put("error", 0); obj.put("url", saveUrl); this.print(obj.toJSONString());
被替换的代码:
FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding("UTF-8"); List items = upload.parseRequest(request); Iterator itr = items.iterator(); while (itr.hasNext()) { ...... }
还有就是KindEditor的FileManager功能,如果你要转移原jsp中的代码至Struts action时,需要注意KindEditor会传递一些Action中并不存在的一些键值,Struts会有对应的warn和exception;
由于FileManager只是对upload成功的文件做一些查询和预览的功能,建议是用servlet替代Struts Action 。
相关文章推荐
- [转]为Kindeditor控件添加图片自动上传功能
- 为KindEditor图片批量上传功能添加排序支持
- ASP中配置Kindeditor上传图片选择添加水印功能
- 为Kindeditor控件添加图片自动上传功能
- Kindeditor编辑器添加图片上传水印功能(php代码)
- 为Kindeditor控件添加图片自动上传功能
- 为百度UE编辑器上传图片添加水印功能
- 为kindeditor上传图片添加水印(PHP版)
- ckeidtor编辑器添加图片上传功能
- kindeditor 去掉网络图片上传功能
- 使用KindEditor的图片上传功能,实现图片上传到专门的图片服务器。
- node.js中实现kindEditor图片上传功能的方法教程
- kindeditor修改图片上传功能(一)
- kindeditor扩展粘贴截图功能&修改图片上传路径并通过webapi上传图片到图片服务器
- ecshop更换升级FCKeditor编辑器到Kindeditor,支持图片批量上传,和百度地图添加
- HTML5 APP应用实现图片上传及拍照上传功能
- .Net语言 APP开发平台——Smobiler学习日志:快速实现应用中的图片、声音等文件上传功能
- kindeditor 去掉网络图片上传功能
- PHP版的kindeditor编辑器加图片上传水印功能
- Kindeditor(版本号4.0.5)编辑器添加上传flv视频功能