JAVA环境下HTML编辑器FCKeditor使用详解本文大部分为转贴,部分为个人使用后发现的问题与理解。使用的是最新的FCKeditor2.6Beta+FCKeditorjava2.3集成的java环境编辑器。这编辑器和csdn博客中使用的一样,只是少了两个功能:恢复上次提交和插入代码。不知道怎么弄的,谁知道可以告诉我。一起交流,我也是刚开始接触这编辑器。本文介绍FCKeditor在Java环境下的使用方法。一、简介功能:所见即所得,支持图片和Flash,工具栏可自由配置,使用简单兼容性:IE5.5+、Firefox1.5+、Safari3.0+、Opera9.50+、Netscape7.1+、Camino1.0+成熟度:使用广泛,被Baidu、CSDN等选用二、下载官方下载首页:,当前版本为2.6Beta,需要下载FCKeditor2.6Beta(FCKeditor_2.6b.zip)和FCKeditor.Java(FCKeditor-2.3.zip)。三、部署本例以WebRoot作为应用根路径,部署后的目录结构如下图所示:1、FCKeditor_2.6b.zip解压,将fckeditor文件夹复制到/WebRoot/下2、FCKeditor-2.3.zip解压,将commons-fileupload.jar和FCKeditor-2.3.jar复制到/WebRoot/WEB-INF/lib/下,将src下面的FCKeditor.tld复制到/WebRoot/WEB-INF/下,把src目录下的java类的复制到project的src目录下3、修改/WebRoot/WEB-INF/web.xml文件,只定义了两个Servlet映射,并且对上传文件的目录和允许哪些文件上传、拒绝哪些文件上传做了设置,请注意,这两个servlet的url-pattern我都在原来代码的前面加上了/fckeditor,这是表示FCKeditor的根目录。另外SimpleUploader中的enabled属性要改成true,允许上传,增加内容如下:init-paramservletservlet-nameConnector/servlet-nameservlet-classcom.fredck.FCKeditor.connector.ConnectorServlet/servlet-classinit-paramparam-namebaseDir/param-nameparam-value/UserFiles//param-value/init-paraminit-paramparam-namedebug/param-nameparam-valuetrue/param-value/init-paramload-on-startup1/load-on-startup/servletservletservlet-nameSimpleUploader/servlet-nameservlet-classcom.fredck.FCKeditor.uploader.SimpleUploaderServlet/servlet-classinit-paramparam-namebaseDir/param-nameparam-value/UserFiles//param-value/init-paraminit-paramparam-namedebug/param-nameparam-valuetrue/param-value/init-paraminit-param4、修改/WebRoot/fckeditor/fckconfig.js,修改部分如下:注意:步骤3、4设置了文件浏览和上传的配置,web.xml中Servlet的url-pattern要和fckconfig.js中的URL引用一致。另外,我也把FCKeditor目录\fckeditor\editor\filemanager\下的connectors文件夹移到了\fckeditor\editor\filemanager\browser\default\目录下,我也不知道这样做有什么用处,但好像不这样做就会发生错误,希望大家指教。param-nameDeniedExtensionsImage/param-nameparam-value/param-value/init-paraminit-paramparam-nameAllowedExtensionsFlash/param-nameparam-valueswf|fla/param-value/init-paraminit-paramparam-nameDeniedExtensionsFlash/param-nameparam-value/param-value/init-paramload-on-startup1/load-on-startup/servletservlet-mappingservlet-nameConnector/servlet-nameurl-pattern/fckeditor/connector/url-pattern/servlet-mappingservlet-mappingservlet-nameSimpleUploader/servlet-nameurl-pattern/fckeditor/simpleuploader/url-pattern/servlet-mappingFCKConfig.LinkBrowserURL=FCKConfig.BasePath+'filemanager/browser/default/browser.html?Connector=/fckeditor/connector';FCKConfig.ImageBrowserURL=FCKConfig.BasePath+'filemanager/browser/default/browser.html?Type=Image&Connector=/fckeditor/connector';FCKConfig.FlashBrowserURL=FCKConfig.BasePath+'filemanager/browser/default/browser.html?Type=Flash&Connector=/fckeditor/connector';FCKConfig.LinkUploadURL='/fckeditor/simpleuploader?Type=File';FCKConfig.ImageUploadURL='/fckeditor/simpleuploader?Type=Image';FCKConfig.FlashUploadURL='/fckeditor/simpleuploader?Type=Flash';四、使用本例使用最直接的js方式,API和TagLib方式参见FCKeditor-2.3.zip解压后_samples下的例子。fckdemo.jsp:%@pagecontentType=text/html;charset=GBK%htmlheadtitleFCKeditorTest/titlescripttype=text/javascriptsrc=/fckeditor/fckeditor.js/script/headbodyformaction=fckdemo.jspmethod=post%Stringcontent=request.getParameter(content);%tablewidth=80%trtdcolspan=4style=''text-align:center''spanscripttype=text/javascriptvaroFCKeditor=newFCKeditor(''content'');//表单的name,取值的依据oFCKeditor.BasePath=''/fckeditor/'';//指定FCKeditor根路径,也就是fckeditor.js所在的路径oFCKeditor.Height=''200'';//指定高度oFCKeditor.ToolbarSet=''Demo'';//指定工具栏,这里使用了自定义的oFCKeditor.Value=%=content==null?:(content.replaceAll(\,''))%;//默认值oFCKeditor.Create();/script/span/td/trtrtdalign=centerinputtype=submitvalue=提交/td/trtrtd /td/trtrtd取值(可直接保存至数据库):/td/trtrtdstyle=padding:10px;%=content%/td/tr/table/form/body/html效果图:其实,我们也可以抛开JavaScript,而在服务器端使用标签来创建Web编辑器了。先在fckdemo.jsp:中引入标签库:再在原来放JavaScript的地方,放如下代码:%@tagliburi==FCK%FCK:editorid=EditorDefaultbasePath=/editor/fckeditor/imageBrowserURL=/editor/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connectorlinkBrowserURL=/editor/fckeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connectorflashBrowserURL=/editor/fckeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connectorimageUploadURL=/editor/fckeditor/editor/filemanager/upload/simpleuploader?Type=ImagelinkUploadURL=/editor/fckeditor/editor/filemanager/upload/simpleuploader?Type=FileflashUploadURL=/editor/fckeditor/editor/filemanager/upload/simpleuploader?Type=FlashThisissomestrongsampletext/strong.Youareusingahref=:editor这里有一点一定要注意,那就是这里的属性都要避免使用相对路径。刷新页面,又见编辑器,此时,可以顺利的上传文件了。整合编辑器的任务到此完成。下一步,就是怎样对编辑器进行更多的控制了。五、配置文件fckconfig.js1、