jFinal+ ckeditor4.8 图片上传

1、前端页面引入 ckeditor4.8 (官网下载)

<textarea rows="10" name="*ckeditor_textarea*" id="texta"></textarea>
<script type="text/javascript">CKEDITOR.replace("*ckeditor_textarea*");</script>

textarea 的 name 与 script中 的 replace 内 保持一致(ckeditor教程有写)

2、修改ckeditor/congif.js文件配置

CKEDITOR.editorConfig = function( config ) {
 config.image_previewText=' '; //预览区域显示内容
 config.filebrowserImageUploadUrl = "/addPromoteImg?type=Image"; //图片上传的 controller(action)
};

3、配置contorller中方法

public void addPromoteImg(){
        String path = PathKit.getWebRootPath().replace("\\", "/");
        path = path.substring(0,path.indexOf("webapps")+8)+"promoteImg/";// promoteImg 为自定义的保存图片路径
        UploadFile file = getFile("upload",path,5* 1024 * 1024,"UTF-8");
        String imgurl="";
        Long fileName = System.currentTimeMillis();
        if(null!=file){
            String sufName = file.getFileName().substring(file.getFileName().lastIndexOf("."),file.getFileName().length());
            String imgPath = path+File.separator+fileName+sufName;
            File dest = new File(imgPath);
            imgurl="/promoteImg/"+fileName+sufName;
            file.getFile().renameTo(dest);

            String callback =getPara("CKEditorFuncNum"); 

            PrintWriter writer = null;
            try {
                HttpServletResponse response = getResponse();
                writer = response.getWriter();
                writer.write("<script type=\"text/JavaScript\">"
                        +"window.parent.CKEDITOR.tools.callFunction("+ callback + ",'" +ADDRESS+ fileName + sufName+"','')"
                        +"</script>");
                writer.flush();
            } catch (IOException e) {
                throw new RenderException(e);
            }
            finally {
                if (writer != null)
                    writer.close();
            }
        }
        renderNull();
    }

ckeditor界面
ckeditor图片管理界面
上传结束

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值