在线HTML文档编辑器使用入门之图片上传与图片管理的实现:
官方网址: http://kindeditor.net/demo.php
开发步骤:
1.开发中只需要导入选中的文件(通常在 webapp 下,建立 editor 文件夹 )
导入:lang、plugins、themes、kindeditor.js/kindeditor-min.js-->放在editor文件夹下
2.在页面上引入相关的js&css文件
<!-- 导入Kindeditor相关文件 -->
<script type="text/javascript" src="../../editor/lang/zh_CN.js"></script>
<script type="text/javascript" src="../../editor/kindeditor.js"></script>
<link rel="stylesheet" href="../../editor/themes/default/default.css" />
3.在页面提供标签<textarea id="ta" name="ta"></textarea>
KindEditor.ready(function(K) {
window.editor = K.create("#ta");
4.定制工具栏按钮显示:
KindEditor.ready(function(K) {
window.editor = K.create("#ta", {
items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
'anchor', 'link', 'unlink', '|', 'about'
],allowFileManager:true,
uploadJson:"../../image_upload.action",
fileManagerJson:"../../image_manager.action"
});
5.上传图片与图片管理功能实现:
页面提供对应方法:
allowFileManager、uploadJson、fileManagerJson-->发送请求到后台action处理:
//提供属性注入
private File imgFile;
private String imgFileFileName;
private String imgFileContentType;
//图片上传方法
@Action(value = "image_upload", results = { @Result(name = "success", type = "json") })
public String uploadImg() throws IOException {
System.out.println("file:" + imgFile);
System.out.println("文件名称:" + imgFileFileName);
System.out.println("文件类型:" + imgFileContentType);
String savePath = ServletActionContext.getServletContext().getRealPath(
"/upload/");
String saveUrl = ServletActionContext.getRequest().getContextPath()
+ savePath;
// 生成随即图片名称
UUID randomUUID = UUID.randomUUID();
String ext = imgFileFileName
.substring(imgFileFileName.lastIndexOf("."));
String randomUrl = randomUUID + ext;
// 保存图片(绝对的路径和)
FileUtils.copyFile(imgFile, new File(savePath + "/" + randomUrl));
// 返回浏览器数据(文件上传成功了还是失败了)
Map<String, Object> map = new HashMap<String, Object>();
map.put("error", 0);
map.put("url", saveUrl + randomUrl);
ServletActionContext.getContext().getValueStack().push(map);
return SUCCESS;
} //图片管理方法
@Action(value = "image_manager", results = { @Result(name = "success", type = "json") })
public String manager() {
// 根目录路径(绝对路径)
String rootPath = ServletActionContext.getServletContext().getRealPath(
"/")
+ "upload/";
// 根目录URL(绝对路径)
String rootUrl = ServletActionContext.getRequest().getContextPath()
+ "/upload/";
List<Map<String, Object>> fileList = new ArrayList<Map<String, Object>>();
// 当前上传目录
File currentPathFile = new File(rootPath);
// 图片的扩展名
String[] fileTypes = new String[] { "gif", "jpg", "jpeg", "png", "bmp" }; if (currentPathFile.listFiles() != null) {
// 遍历目录取的文件信息
for (File file : currentPathFile.listFiles()) {
Map<String, Object> hash = new HashMap<String, Object>();
String fileName = file.getName();
if (file.isDirectory()) {
hash.put("is_dir", true);
hash.put("has_file", (file.listFiles() != null));
hash.put("filesize", 0L);
hash.put("is_photo", false);
hash.put("filetype", "");
} else if (file.isFile()) {
String fileExt = fileName.substring(
fileName.lastIndexOf(".") + 1).toLowerCase();
hash.put("is_dir", false);
hash.put("has_file", false);
hash.put("filesize", file.length());
hash.put("is_photo", Arrays.<String> asList(fileTypes)
.contains(fileExt));
hash.put("filetype", fileExt);
}
hash.put("filename", fileName);
hash.put("datetime",
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(file
.lastModified()));
fileList.add(hash);
}
}
Map<String, Object> result = new HashMap<String, Object>();
result.put("moveup_dir_path", "");
result.put("current_dir_path", rootPath);
result.put("current_url", rootUrl);
result.put("total_count", fileList.size());
result.put("file_list", fileList);
ActionContext.getContext().getValueStack().push(result);
return SUCCESS;
}

在线HTML文档编辑器使用入门之图片上传与图片管理的实现的更多相关文章

  1. 推荐ajaxfilemanager for tiny_mce 比较完善的tiny_mce编辑器的图片上传及图片管理插件PHP版 支持中文

    tiny_mce编辑器,我觉得挺简洁.好用的,但就是图片上传的插件是收费的,而且网上找了半天也没有找到开源好用的上传插件. 不过功夫不负有心人,终于还就被我找到一款相当满意的插件. 这个插件的名字叫a ...

  2. swagger在线api文档搭建指南,用于线上合适么?

    在上一篇文章中,我们讲解了什么是 api,什么是 sdk: https://www.cnblogs.com/tanshaoshenghao/p/16217608.html 今天将来到我们万丈高楼平地起 ...

  3. 解决SharePoint 文档库itemadded eventhandler导致的上传完成后,编辑页面保持报错的问题,错误信息为“该文档已经被编辑过 the file has been modified by...”

    在文档库中添加itemadded 后,在上传文件后,会自动打开文档属性的编辑页面,在保存的时候就会报错,说这个文档已经被编辑过了.这是应为默认itemadded实践是异步执行的,会在edit页面打开之 ...

  4. 从web编辑器 UEditor 中单独提取图片上传,包含多图片单图片上传以及在线涂鸦功能

    UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具有轻量,可定制,注重用户体验等特点,开源基于MIT协议,允许自由使用和修改代码.(抄的...) UEditor是非常好用的富文 ...

  5. 使用百度UMeditor富文本编辑器,修改自定义图片上传,修改源码

    富文本编辑器,不多说了,这个大家应该都用到过,至于用到的什么版本,那就分很多种 CKEditor:很早以前叫FCK,那个时候也用过,现在改名了,比较流行的一个插件,国外很多公司在用 UEDITOR:百 ...

  6. C# 10分钟入门基于WebOffice实现在线编辑文档,实时保存到服务器(所有office,兼容WPS)

    今天,他来了(weboffice在线编辑文档). 上次写了一个在线预览的博,当然,效果并不是太理想,但是紧急解决了当时的问题. 后来,小编重新查找资料,求助大牛,终于使用新的方式替换了之前的low方法 ...

  7. (六)在线文档编辑器的使用和数据字典(ueditor编辑器/my97datepicker日期控件)

    使用ueditor编辑器注意: 1. 要把ueditor的jar包添加到WEB-INF/lib里. 2. 在做图片上传等功能时,必须重写struts的过滤器,否则图片流会被拦截程序无法得到图片. 3. ...

  8. Jeecg社区wiki在开放,最终能够在线看文档啦!!!

    Jeecg社区wiki在开放,最终能够在线看文档啦! .! 2014-12-18 scott JEECG jeecg开源社区wiki正式启动了.方便大家看文档 訪问地址是: http://osbaba ...

  9. 使用swagger实现web api在线接口文档

    一.前言 通常我们的项目会包含许多对外的接口,这些接口都需要文档化,标准的接口描述文档需要描述接口的地址.参数.返回值.备注等等:像我们以前的做法是写在word/excel,通常是按模块划分,例如一个 ...

随机推荐

  1. IO模型《三》非阻塞IO

    非阻塞IO(non-blocking IO) Linux下,可以通过设置socket使其变为non-blocking.当对一个non-blocking socket执行读操作时,流程是这个样子: 从图 ...

  2. python index()函数

    python内置index()函数 index() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,该方法与 python ...

  3. php数据库编程---mysqli扩展库

    1,mysqli扩展库允许我们访问MySQL数据库,并对MySql数据库进行curd操作.Mysqli扩展库比mysql扩展库加强了. 2,mysqli扩展库和mysql扩展库的比较 (1) mysq ...

  4. Your branch is ahead of 'origin/master' by 1 commit.

    git reset HEAD^ --soft git reset HEAD^ --hard --soft 表示保留当前commit,重新commit --hard 表示丢弃当前add,重新add.co ...

  5. UITouch笔记

    UITouch是什么 表示在在屏幕上触摸事件,包括触摸的位置.大小.力度(3D touch).运动. 在一系列触摸事件中,UITouch都是同一个,但是不要retain某一个UITouch.如果要保存 ...

  6. Python爬取网上车市[http://www.cheshi.com/]的数据

    #coding:utf8 #爬取网上车市[http://www.cheshi.com/]的数据 import requests, json, time, re, os, sys, time,urlli ...

  7. ORACLE中的KEEP()使用方法

    转载至:http://blog.csdn.net/aqszhuaihuai/article/details/6434160 ====================================== ...

  8. POJO和Javabean的区别:

    pojo:存粹java类,不继承,不实现.(不受限制的java类),多用于指数据库的映射对象javaBean:可复用组件,由容器(tomcat)创建,因此应具有无参构造器,不能跨进程访问,通常要无方法 ...

  9. JAVA JVM 杂谈(一)

    JVM能够跨计算机体系结构来执行Java字节码,主要是由于JVM屏蔽了与各个计算机平台先关的软件或者硬件之间的差异,使得与平台先关的耦合统一由JVM的提供者来实现. JVM结构组成: 1.类加载器:在 ...

  10. 进阶篇:4.3)DFA设计指南:防错设计( 防呆设计)

    本章目的:每一个装配步骤都有设计防错. 1.前言 关于防错设计,作者有想说的话: 1)防错设计是DFA重要的一条.因为太过重要,作者单独开一分章写! 2)只有理解了设计防错的重要,才会去设计防错特征. ...