富文本编辑器图片上传回显,内容回显更新

/var editor;  
// 编辑器参数
var kingEditorParams = {
//指定上传文件参数名称
filePostName  : "uploadFile",
//指定上传文件请求的url。
uploadJson : '/upload/uploadFck',
//上传类型,分别为image、flash、media、file
afterUpload: function(){this.sync();}, //图片上传后,将上传内容同步到textarea中


}; 
    $(function() {  
          editor = KindEditor.create('textarea[name="content"]',kingEditorParams,{resizeType : 1,width:"100%",height:"200px",afterChange:function(){  
         this.sync();  
           },afterBlur:function(){  
               this.sync();  
           }});  
    }); 





@RequestMapping(value = "/uploadFck")
public void uploadFck(HttpServletRequest request,HttpServletResponse response) throws Exception{
//无敌接收图片
//Spring提供 MultipartRequest
MultipartRequest mr = (MultipartRequest)request;
String realPath = request.getSession().getServletContext().getRealPath(Constants.IMG_URL);
//只有图片
Map fileMap = mr.getFileMap();
Set> entrySet = fileMap.entrySet();
for (Entry entry : entrySet) {
MultipartFile pic = entry.getValue();
String fileName = UUID.randomUUID().toString().replaceAll("-", "")+".jpg";
pic.transferTo(new File(realPath+fileName));
//回显到富文编辑器上 json
JSONObject jo = new JSONObject();
jo.put("url", Constants.IMG_URL + fileName);
jo.put("error", 0);
//回调图片
response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(jo.toString());
}

你可能感兴趣的:(java)