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

来源:互联网 发布:战国之怒进阶数据 编辑:程序博客网 时间:2024/06/04 18:29
/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();  
           }});  
    }); 


<textarea rows="3" style="width:100%;"  id="content" name="content">${page.content }</textarea>



@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<String, MultipartFile> fileMap = mr.getFileMap();
Set<Entry<String, MultipartFile>> entrySet = fileMap.entrySet();
for (Entry<String, MultipartFile> 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());
}

原创粉丝点击