KindEditor.ready(function(K) {
var editor1 = K.create('textarea[name="content1"]', {
cssPath : '../plugins/code/prettify.css',
uploadJson : '../jsp/upload_json.jsp',
fileManagerJson : '../jsp/file_manager_json.jsp',
allowFileManager : true,
afterCreate : function() {
var self = this;
K.ctrl(document, 13, function() {
self.sync();
document.forms['example'].submit();
});
K.ctrl(self.edit.doc, 13, function() {
self.sync();
document.forms['example'].submit();
});
}
});
prettyPrint();
});
1.先将allowFileManager 即是否接受文件上传改为true
2.uploadJson即为上传图片点击确定按钮后要转入的action请求(用于将本地图片上传至服务器,同时返回图片地址)
3.最后在action中上传完图片后利用json串返回图片地址
JSONObject obj = new JSONObject();
obj.put("error", 0);//0为上传成功表示
obj.put("url", saveUrl + newFileName);
response.write(obj.toJSONString());
response.end();
注意:当上传图片出错时,
obj.put("error", 1);
obj.put("message","上传失败");
这样就可以把错误信息返回到页面