CKEditor 3.x 在Java中配置、包括图片上传、支持FTP、图片压缩(转)
备注:不支持附件,如需附件请移至我的资源库
http://download.csdn.net/detail/jiangjiayong/3871706
CKEditor 3.x配置说明
?基本使用:
1、所需文件架包
A. Ckeditor基本文件包,比如:ckeditor_3.6.2.zip
下载地址:http://ckeditor.com/download
2、配置使用
A.将下载下来的CKEditor压缩解压,将解压后的文件夹(“ckeditor”)拷贝进项目里面,比如我是放在”WebContent”的”commons”文件夹下;
B.在需要使用CKEditor的页面引入CKEditor的支持javascript
<head><script type="text/javascript"src="/commons/ckeditor/ckeditor.js"></script></head>
<textarea id="editor1" name="editor1">Initial value.</textarea><script type="text/javascript">CKEDITOR.replace(“editor1”);</script>
<%@ taglib uri="http://ckeditor.com"prefix="ckeditor"%>
<textareaid="id_1" name="id_1">Initial value.</textarea> <ckeditor:replacereplace="id_1" basePath="/commons/ckeditor/" />
<textareaid="id_1" name="id_1">Initial value.</textarea> <ckeditor:replacereplace="id_1" basePath="/commons/ckeditor/" />
function Done() { window.returnValue = imgPath; //上传后的图片链接 window.close();}
# default allowed extensions settings ckeditor.resourceType.media.extensions.allowed =.aiff|.asf|.avi|.bmp|.fla|.flv|.gif|.jpeg|.jpg|.mid|.mov|.mp3|.mp4|.mpc|.mpeg|.mpg|.png|.qt|.ram|.rm|.rmi|.rmvb|.swf|.tif|.tiff|.wav|.wma|.wmv # base directory for the user files relative to the context root ckeditor.userFilesPath =/files/ckeditor/ # default encoding ckeditor.encoding =UTF-8 # default file size threshold : 1*1024*1024 = 1048576 ckeditor.size.threshold =1048576 # default one file size : 5*1024*1024 = 52428800 ckeditor.file.size.max =52428800 # default all files size : 10*1024*1024 = 10485760 ckeditor.size.max =10485760 # some messages message.request.not.contain.images =Request does not contain image or media file. message.request.general.form =Request is the general form. message.request.file.max =One file is too large. message.request.all.file.max =All files is too large. # ftp configurations # open ftp file upload is true otherwise false ftp.upload =true ftp.server =127.0.0.1 ftp.user_name =jjy ftp.password =123 ftp.port =21 # image resize configurations # open image resize is true otherwise false image.resize =true # resizeByMaxSize:0,resizeByRatio:1,resizeByFixedWidth:2,resizeByFixedHeight:3 image.resize.type =0 # resize size 100,120,240,400,640 image.resize.size =120,240,400
CKEDITOR.editorConfig = function(config) { //获取项目的目录比如:http://www.mymyty.com varstrFullPath = window.document.location.href; varstrPath = window.document.location.pathname; varpos = strFullPath.indexOf(strPath); varprePath = strFullPath.substring(0,pos); varpostPath = strPath.substring(0,strPath.substr(1).indexOf('/')+1); varpath_url = prePath+postPath; //显示出图片上传模块 config.pasteFromWordRemoveStyles = true; config.filebrowserImageUploadUrl = path_url + "/commons/ckeditor/images/upload.html"; //为图片上传处理Servlet在web.xml中配置 // 去掉ckeditor“保存”按钮 config.removePlugins = 'save'; };
<servlet> <servlet-name>ckeditor</servlet-name> <servlet-class>com.ebiz.ssi.ckeditor.CkeditorImagesUploadServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ckeditor</servlet-name> <url-pattern>/commons/ckeditor/images/upload.html</url-pattern> </servlet-mapping>
<%@ taglib uri="http://ckeditor.com"prefix="ckeditor"%>
<textarea id="id_1" name="id_1">Initial value.</textarea> <ckeditor:replacereplace="id_1" basePath="/commons/ckeditor/" />
config.language = 'zh-cn'; //编辑器语言config.width = 600; //初始化时的宽度config.height = 400; //初始化时的高度config.skin='kama'; //编辑器样式,有三种:’kama’(默认)、’office2003′、’v2′config.tabSpaces = 4; config.resize_maxWidth = 600; //如果设置了编辑器可以拖拽这是可以移动的最大宽度config.toolbarCanCollapse = false; //工具栏可以隐藏//config.toolbarLocation = 'bottom'; //可选:设置工具栏在整个编辑器的底部bottomconfig.resize_minWidth = 600; //如果设置了编辑器可以拖拽这是可以移动的最小宽度config.resize_enabled = false; //如果设置了编辑器可以拖拽 // 下面是编辑器工具栏配置,"/"代表换行config.toolbar_Full = [ ['Source','-','Save','NewPage','Preview','-','Templates'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], '/', ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['Link','Unlink','Anchor'], ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'], '/', ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'] ];//以下是后添加的验证非法数据config.protectedSource.push(/<\s*iframe[\s\S]*?>/gi); //<iframe> tags. config.protectedSource.push(/<\s*frameset[\s\S]*?>/gi) ; // <frameset> tags.config.protectedSource.push(/<\s*frame[\s\S]*?>/gi) ; // <frame> tags.config.protectedSource.push(/<\s*script[\s\S]*?\/script\s*>/gi) ; // <SCRIPT> tags.config.baseFloatZIndex = 10000; // 编辑器的z-index值config.baseHref = “”; //设置是使用绝对目录还是相对目录,为空为相对目录