CKEditor使用

1.实例已存在报错

if(CKEDITOR.instances.contenttexts){
		addCkeditor("contenttexts");
	}else{
		CKEDITOR.replace('contenttexts');
	}
	 
	function addCkeditor(id){   
	    var editor2 = CKEDITOR.instances[id];   
		if(editor2) editor2.destroy(true);//销毁编辑器 content2,然后新增一个
        editor = CKEDITOR.replace(id);   
 }

2.图片上传

在 config.js 里面 加上:

	config.image_previewText = ' ';
	config.filebrowserUploadUrl = "admin/system/upload";
	var pathName = window.document.location.pathname;
	var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    config.filebrowserImageUploadUrl = projectName+'/system/upload.do'; //固定路径

Action地址固定

@Controller
@RequestMapping("/system")
public class UpLoadImgAction {
	public static final Long maxFileSize = XX;	
	public static final Long maxVideoSize = XX;	
	@RequestMapping("/upload")
	public void uploadImg(HttpServletRequest request,HttpServletResponse response,@RequestParam("upload") MultipartFile[] File) throws IOException{
		String realpath = request.getSession().getServletContext()
				.getRealPath("/");//服务存图片的文件夹地址
		if (File != null && lFile.length > 0) {
			if (!File[0].isEmpty()) {
				long length = File[0].getSize();
				if (length > maxFileSize) {
					String jsht = "<script>alert('上传的图片过大(超700k),提交失败');</script>";
					PublicSubfun.writehtml(jsht, response);
				}
				String[] type = File[0].getContentType().split("/");
				File f = new File(realpath + "/" + System.currentTimeMillis()
						+ "." + type[1]);
				FileUtils.copyInputStreamToFile(picurlFile[0].getInputStream(),
						f);
			   String url = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/服务存图片的文件夹地址/" + f.getName();
			   StringBuffer sb = new StringBuffer();
               sb.append("<script type=\"text/javascript\">");
               sb.append("window.parent.CKEDITOR.tools.callFunction("+ CKEditorFuncNum + ",'" +url + "','')"); 
               sb.append("</script>");
               PublicSubfun.writehtml(sb.toString(),response);}
		 }
	}
}



</pre><pre>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值