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