1、下载 KindEditor 最新版本,下载页面: http://www.kindsoft.net/down.php
2、解压 kindeditor-x.x.x.zip 文件,将所有文件加入工程/webapp/include/js中。删除不需要的文件夹(php,asp等)我们是java工程保留jsp文件夹。
3、将jsp文件夹中的file_manager_json.jsp、upload_json.jsp剪切到kindeditor-4.1.10目录下,将jsp中lib下的三个jar包加入工程方法为;
在pom.xml中添加代码
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
4、找到file_manager_json.jsp中rootPath和rootUrl
//根目录路径,可以指定绝对路径,比如 /var/www/attached/
String rootPath = pageContext.getServletContext().getRealPath("/") + "upload/";
//根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
String rootUrl = request.getContextPath() + "/upload/";
添加引用<%@ page import="org.json.JSONObject" %> 将字符串错误修改为toString。
5、找到upload _json.jsp中rootPath和rootUrl
//根目录路径,可以指定绝对路径,比如 /var/www/attached/
String rootPath = pageContext.getServletContext().getRealPath("/") + "upload/";
//根目录URL,可以指定绝对路径,比如 http://www.yoursite.com/attached/
String rootUrl = request.getContextPath() + "/upload/";
添加引用<%@ page import="org.json.JSONObject" %> 将字符串错误修改为toString。
6、在kindeditor-4.1.10/ plugins/ image下找到image.js,
修改uploadJson 为uploadJson = K.undef(self.uploadJson, self.basePath + 'file_manager_json.jsp'),
7、同样在media、flash、insertfile中做同样修改。
8、在需要添加kindeditor的页面中添加
<script charset="utf-8" src="${base}/include/js/kindeditor-4.1.10/kindeditor.js"></script>
<script charset="utf-8" src="${base}/include/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
<SCRIPT type="text/javascript">
KindEditor.ready(function(K) {
K.create('textarea[name="content"]', {
autoHeightMode : true,
uploadJson :'${base}/include/js/kindeditor-4.1.10/upload_json.jsp',
fileManagerJson : '${base}/include/js/kindeditor-4.1.10/file_manager_json.jsp',
afterCreate : function() {
this.loadPlugin('autoheight');
}
});
});
</SCRIPT>
在body中添加
<tr>
<textarea name="content" style="width:300px;height:200px;"></textarea></tr>
9、成功效果图