CKEditor3.6.4配置及在网站中的使用(三)

//FileBrowser.jsp

    <%@pageimport="java.io.File"%>  

    <%@pagelanguage="java"contentType="text/html; charset=GB18030"  

        pageEncoding="GB18030"%>  

    <!DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">  

    <html>  

    <head>  

    <metahttp-equiv="Content-Type"content="text/html; charset=GB18030">  

    <metahttp-equiv="pragma"content="no-cache">  

    <metahttp-equiv="cache-control"content="no-cache">  

    <metahttp-equiv="expires"content="0">  

    <title>图片浏览</title>  

    <scripttype="text/javascript">  

    //这段函数是重点,不然不能和CKEditor互动了  

    functionfunCallback(funcNum,fileUrl){  

        varparentWindow = ( window.parent == window ) ? window.opener : window.parent;  

        parentWindow.CKEDITOR.tools.callFunction(funcNum, fileUrl);  

        window.close();  

    }  

    </script>  

    </head>  

    <body>  

    <%  

        String path = request.getContextPath() + "/";  

        String type = "";  

        if(request.getParameter("type") != null)//获取文件分类  

            type = request.getParameter("type").toLowerCase() + "/";  

        String clientPath = "UserFiles/"+ type;  

        File root = newFile(request.getSession().getServletContext().getRealPath(clientPath));  

        if(!root.exists()){  

            root.mkdirs();  

        }  

        String callback = request.getParameter("CKEditorFuncNum");  

        File[] files = root.listFiles();  

        if(files.length > 0){  

            for(File file:files ) {  

                String src = path + clientPath + file.getName();  

                out.println("<img width='110px' height='70px' src='http://guaihubao.blog.163.com/"+ src + "' alt='"+ file.getName() + "' onclick=\"funCallback("+callback+",'"+ src +"')\">");  

            }  

        }else{  

            out.println("<h3>未检测到资源。</h3>");  

        }  

     %>  

    </body>  

</html>  

到此,整个ckeditor的配置就算结束。配置ckeditor很重要的一点就是路径问题,如果配置正确无法显示编辑器肯定在引入js的文件的时候出现了路径问题。如果在上传或者浏览服务器文件的时候出现错误,应该就是自定义的两个数据接口的路径配置错误,需要重新配置一下路径。

和数据库对接的接口代码我就不在此赘述了,直接使用jsp文件或者servlet获取编辑页面的编辑器的textarea的那么值就可以了,然后就可以写入数据库或者写成文件。从数据库读出来的时候可以直接在驾驶平页面使用out.write()也可以使用servlet生成页面。有好多种方法实现,就看自己习惯使用哪一种了。

至此,整个ckeditor就算配置完毕可以正常使用了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值