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

//FileBrowser.jsp

    <%@page import="java.io.File"%> 

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

        pageEncoding="GB18030"%> 

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

    <html> 

    <head> 

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

    <meta http-equiv="pragma" content="no-cache"> 

    <meta http-equiv="cache-control" content="no-cache"> 

    <meta http-equiv="expires" content="0"> 

    <title>图片浏览</title> 

    <script type="text/javascript"> 

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

    function funCallback(funcNum,fileUrl){ 

        var parentWindow = ( 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就算配置完毕可以正常使用了。

posted @ 2012-12-20 11:24  矢风快乐  阅读(169)  评论(0)    收藏  举报