ckeditor图片上传

今天第一次使用ckeditor文本编辑器,使用过程中遇到了很多麻烦,我使用的是servlet进行图片的上传和数据的接受,相信大家在服务器端接收数据的时候会遇到很多麻烦。下面就我遇到的问题和大家分享一下:
第一:使用ckeditor获得数据之后:传送到服务器端的时候往往会有很多换行空格等等,这样存入数据库,如果你用json传输的话会出现问题,所以要对这个空格换行进行处理,简单的处理方法是:
content.replaceAll("\n[ \t]*","")//content为获得的内容
使用ckeditor获得数据也给罗列下吧:
设置内容:
CKEDITOR.instances.editor1.setData("<p>11</p>");
获取内容:
CKEDITOR.instances.editor1.getData();


第二:使用ckeditor进行文件上传:
代码:
[size=large] var config = {
filebrowserImageUploadUrl : 'upload.do'
};
var editor1,editor2,html= '';
editor1=CKEDITOR.appendTo('editor1', config, html );[/size]
//其中editor1为html中放入ckeditor的编辑器的div的id
//upload.do为访问的servlet中的url


在servlet中代码为:
[size=large] public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("utf-8");
String Path = new upLoadImg(request).doUpload();
String callback = request.getParameter("CKEditorFuncNum");
out.println("<script type=\"text/javascript\">");
out.println("window.parent.CKEDITOR.tools.callFunction(" + callback
+ ",'" + Path + "',''" + ")");
out.println("</script>");
out.flush();
out.close();
}[/size]
其中:path为上传之后得到的图片路径

[img]http://dl.iteye.com/upload/attachment/532476/398df19f-6d02-325f-95e0-14bd43c962f2.jpg[/img]

其实在网上找了很多代码,这样使用图片上传是最最简单的运用
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值