于是网上搜索,找到一些文章,但配置时或多或少都是还是有问题,于是结合网友的文章和自己配置过程,记录下来。
一:从官方网站下载fckeditor核心文件 ,http://ckeditor.com/download,现在最新版本是2.6.6
二:下载java版的文件上传组件 ,http://sourceforge.net/projects/fckeditor/files/FCKeditor.Java/2.6/
三:下载最后一个jar包 :www.slf4j.org/dist/ ,找到slf4j-1.5.8.zip,下载就行了。(其实这个已经不用单独下载了,在fckeditor-java-demo-2.6.war文件中已包含该jar包)
准备文件已全部下载好了,下面开始配置吧,
四:基本配置与优化 ,解压FCKeditor_2.6.6.zip,会得到一个文件夹fckeditor,全部拷贝到工程的根目录下,只保留fckconfig.js,fckeditor.js,fckstyles.xml,fcktempletes.xml,fckpackager.xml和 fckeditor文件夹,删除所有以“_”开头的文件和文件夹 ,(这是测试或demo或是 temp文件,无用),
五: 解压fckeditor-java-demo-2.6.war,拷贝lib下的所有xx.jar到,你的项目/web-inf/lib下
六: 解压slf4j-1.5.8.zip,拷贝slf4j-jdk14-1.5.8.jar到,你的项目 /web-inf/lib下。这一步也可以略过了!
七:编辑web.xml ,加入(新版本的去掉了很多东西,用以前版本的方法,在web.xml文件中进行参数配置已经没用了,试过很多参数都没用)
- <servlet>
- <servlet-name>FCKConnector</servlet-name>
- <servlet-class>net.fckeditor.connector.ConnectorServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>FCKConnector</servlet-name>
- <url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>
- </servlet-mapping>
八:创建fckeditor.properties文件, 在src下(编译之后处于 classes目录中),加入
connector.userActionImpl = net.fckeditor.requestcycle.impl.UserActionImpl
注:default.properties可以在fckeditor-java-core-2.5.jar的net/fckeditor /handlers/找到
九:配置完毕 ,开始使用吧
我试了两种方法:
1,在</head>前面添加如下代码
- <script type="text/javascript" src="<%=basePath%>/fckeditor/fckeditor.js"></script>//这里在路径前面加上了="<%=basePath%>,解决了写绝对路径的麻烦
- <script type="text/javascript">
- window.onload = function()
- {
- var oFCKeditor = new FCKeditor( 'content','100%','400','Default' ) ;
- oFCKeditor.BasePath = "<%=basePath%>/fckeditor/" ;//该路径指示fckeditor的根路径,这里在路径前面加上了="<%=basePath%>,解决了写绝对路径的麻烦
- //这里content和下面的textarea的name参数必须对应
- //后面依次是宽、高和工具栏设置可以是Default或Basic
- oFCKeditor.ReplaceTextarea() ;
- }
- </script>
然后在需要显示编辑器的地方插入:
- <textarea name="content"><!--这里是输入框的默认值--></textarea>"><!--content和上面的一定得对应起来,这里的content就是表单传递的参数名-->
2,这个是fckeditor-java-demo-2.6.war中本身带的例子:
在</head>前插入
- <script type="text/javascript">
- function FCKeditor_OnComplete(editorInstance) {
- window.status = editorInstance.Description;
- }
- </script>
表单写法如下:
- <form action="sampleposteddata.jsp" method="post" target="_blank">
- <div><input id="EditorDefault" name="EditorDefault" value="This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net">FCKeditor</a>." type="hidden" /><iframe id="EditorDefault___Frame" frameborder="0" height="200" scrolling="no" width="100%" src="/fckeditor-java-demo-2.6/fckeditor/editor/fckeditor.html?InstanceName=EditorDefault&Toolbar=Default"> </iframe></div>
- <br />
- <input type="submit" value="Submit" /></form>
就这些,我就是按照该步骤配置成功的!
通过以上这些配置,fckeditor所以功能已经可以正常使用了,但如果要设置Fckeditor的运行参数,还得继续做一些设置工作,像编辑器的工具栏风格,按钮布局,字体,表情图片等,都可以通过fckconfig.js进行设置。但有些参数,如上传文件路径,文件自动重命名,等还需要用到另外一个重要文件fckeditor.properties。
当然,Fckeditor是开源的,你可以自己下载源代码,修改相应的文件,或者用别人修改好的东西。这里主要介绍一种设置的方法。
新版本的2.6.6的,好像做了很多调整,如SimpleUploader好像已经去掉了,以前很多设置都是基于这个的。前面通过web.xml配置SimpleUploader和servlet,也成功了,但很多功能不太正常,呵呵,扯远了,回到主题。
至于Fckconfig.js的设置方法网上有很多,这里也有一篇http://www.solnis.com/article/tech/158.htm
fckeditor.properties文件是配置时必须的,直接放在src目录下,编译的时候会编译到calsses目录去的。在fckeditor-java-2.6-src.tar.gz里解压后java-core/src/main/resources/net/fckeditor/handlers下面有个default.properties文件,能设置的参数都在这个文件里了,内容如下
- #
- # FCKeditor - The text editor for Internet - http://www.fckeditor.net
- # Copyright (C) 2004-2010 Frederico Caldeira Knabben
- #
- # == BEGIN LICENSE ==
- #
- # Licensed under the terms of any of the following licenses at your
- # choice:
- #
- # - GNU General Public License Version 2 or later (the "GPL")
- # http://www.gnu.org/licenses/gpl.html
- #
- # - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
- # http://www.gnu.org/licenses/lgpl.html
- #
- # - Mozilla Public License Version 1.1 or later (the "MPL")
- # http://www.mozilla.org/MPL/MPL-1.1.html
- #
- # == END LICENSE ==
- #
- # Default properties for FCKeditor.Java
- #
- # @version $Id: default.properties 4785 2009-12-21 20:10:28Z mosipov $
- # default allowed extensions settings
- connector.resourceType.file.extensions.allowed = 7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip
- connector.resourceType.image.extensions.allowed = bmp|gif|jpeg|jpg|png
- connector.resourceType.flash.extensions.allowed = swf|fla
- connector.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
- # default resource type paths
- connector.resourceType.file.path = /file
- connector.resourceType.image.path = /image
- connector.resourceType.flash.path = /flash
- connector.resourceType.media.path = /media
- # Due to security issues with Apache modules, it is recommended to leave this
- # setting enabled.
- connector.forceSingleExtension = true
- # base URL path for the userfiles
- connector.userFilesPath = /userfiles
- # base system path on the backend for the userfiles
- connector.userFilesAbsolutePath = /userfiles
- # Instructs the Connector to check, if the uploaded image is really one
- connector.secureImageUploads = true
- # directory of the editor relative to the context root
- fckeditor.basePath = /fckeditor
- # default height of the editor
- fckeditor.height = 200
- # default toolbar set of the editor
- fckeditor.toolbarSet = Default
- # default width of the editor
- fckeditor.width = 100%
- # default implementations
- connector.impl = net.fckeditor.connector.impl.ContextConnector
- connector.userActionImpl = net.fckeditor.requestcycle.impl.DisabledUserAction
- connector.userPathBuilderImpl = net.fckeditor.requestcycle.impl.ContextPathBuilder
- localization.localeResolverImpl = net.fckeditor.localization.impl.AcceptLanguageHeaderResolver
我修改后的
- #
- # FCKeditor - The text editor for Internet - http://www.fckeditor.net
- # Copyright (C) 2004-2010 Frederico Caldeira Knabben
- #
- # == BEGIN LICENSE ==
- #
- # Licensed under the terms of any of the following licenses at your
- # choice:
- #
- # - GNU General Public License Version 2 or later (the "GPL")
- # http://www.gnu.org/licenses/gpl.html
- #
- # - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
- # http://www.gnu.org/licenses/lgpl.html
- #
- # - Mozilla Public License Version 1.1 or later (the "MPL")
- # http://www.mozilla.org/MPL/MPL-1.1.html
- #
- # == END LICENSE ==
- #
- # @version $Id: fckeditor.properties 4785 2009-12-21 20:10:28Z mosipov $
- # 允许上传的文件类型
- connector.resourceType.file.extensions.allowed = 7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip
- connector.resourceType.image.extensions.allowed = bmp|gif|jpeg|jpg|png
- connector.resourceType.flash.extensions.allowed = swf|fla|flv
- connector.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
- # 上传资源默认路径
- connector.resourceType.file.path = /files
- connector.resourceType.image.path = /image
- connector.resourceType.flash.path = /flash
- connector.resourceType.media.path = /media
- # 强制一个文件名只能有一个“.”符号
- # Due to security issues with Apache modules, it is recommended to leave this
- # setting enabled.
- connector.forceSingleExtension = true
- # 默认的上传路径,为上下文的相对路径,设置上传后的文件链接
- connector.userFilesPath = /Uploadfiles
- # 上传文件的物理路径,相对于文件系统而言,设置上传文件的路径-base system path on the backend for the userfiles
- connector.userFilesAbsolutePath = /Uploadfiles
- # 是否显示全路径
- connector.fullUrl = false
- # 这个如果设置为true,则Fckeditor会检查目录中是否有相同的文件,如果有就
- # 会对这个文件进行重命名
- connector.secureImageUploads = true
- # fckeditor相对于Context的路径
- fckeditor.basePath = /fckeditor
- # fckeditor的默认高度
- #fckeditor.height = 200
- # 默认的工具栏
- #fckeditor.toolbarSet = Default
- # 默认的宽度
- #fckeditor.width = 100%
- #上传文件必须参数,这个参数很重要,默认情况是disabledUserAction,是无法上传文件的,上传会提示无权限
- connector.userActionImpl = net.fckeditor.requestcycle.impl.EnabledUserAction
- # 默认设置的几个参数
- connector.impl = net.fckeditor.connector.impl.ContextConnector
- connector.userPathBuilderImpl = net.fckeditor.requestcycle.impl.ContextPathBuilder
- localization.localeResolverImpl = net.fckeditor.localization.impl.AcceptLanguageHeaderResolver
- # 一些提示信息
- message.enabled_tag.compatible_browser.no = 你的浏览器不兼容!
- message.enabled_tag.compatible_browser.yes = 你的浏览器完全兼容!
- message.enabled_tag.connector.file_browsing.disabled = The Connector is disabled for FileBrowsing
- message.enabled_tag.connector.file_browsing.enabled = The Connector is enabled for FileBrowsing
- message.enabled_tag.connector.file_upload.disabled = The Connector is disabled for FileUpload
- message.enabled_tag.connector.file_upload.enabled = The Connector is enabled for FileUpload
至此,已经全部配置完成啦!
部分内容,参照了这里:http://blog.youkuaiyun.com/collonn/archive/2010/03/26/5419322.aspx