码迷,mamicode.com
首页 > Web开发 > 详细

jFinal+ ckeditor4.8 图片上传

时间:2016-05-12 18:53:01      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:

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();
    }

技术分享
技术分享
技术分享

jFinal+ ckeditor4.8 图片上传

标签:

原文地址:http://blog.csdn.net/qq6255642/article/details/51351972

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!