关于FckEditor for java的配置,如何与自己的项目进行整合,类似于这类文章,在网上有很多。但是,很多人都是抄来抄去,自己根据没有测试和验证配置的可行性,错误百出。更为主要的是,那些抄来抄去的配置,都是早已过时的FckEditor for java 2.3配置方法,甚至更早。现在FckEditor已经是2.6版本了,其包名都由com.fredck.FCKeditor改为net.fckeditor了。
我目前也正在做一个项目,项目中要用到FckEditor,花了一点时间来配置和将其整合到项目中。回头我将整个详细的配置过程也整理了一下,希望可以填补这方面的空缺,并希望大家不要抄来抄去的,发表一篇技术文章,要有依据,要保证文章的质量。
FckEditor for java 2.6版本相对于之前的2.3版本而言,有了许多的改变,这些改变使得我们的Fckeditor配置起来更方便。例如:文件上传SimpleUploaderServle整合到了ConnectorServlet里面,WEB.XML的配置就简单多了。好了,废话少说,下面通过一个实例说明配置详细步骤。
FckEditor的相关包下载
1、访问http://ckeditor.com/download,下载FCKeditor的最新版本,当前FCKeditor的最新版本是FckEditor2.6.6。这个压缩包就是可视化的FckEditor编辑器源码包,支持jsp、php、asp等多种语言。
2、访问http://sourceforge.net/projects/fckeditor/files/FCKeditor.Java/,下载fckeditor-java-2.6。会有三种版本可供下载,分别是fckeditor-java-demo-2.6.war(demo包)、fckeditor-java-2.6-src.zip(源代码版)、fckeditor-java-2.6-bin.zip(发行版)。为了避免出错,最好使用fckeditor-java-demo-2.6.war,因为这个demo是可以正常运行起来的,因为我们在配置的时候要使用到这个demo包中的几个lib类库。
下载之后分别为:FCKeditor_2.6.6.zip 和FCKeditor-java-demo-2.6.war,用WinRAR将它们分别解压。
配置FckEditor并与项目整合
3、在Eclipse(或者其他的IDE)下建立一个新项目,例如:fckeditorTest,即http://localhost:8080/FckeditorTest。
现在将解压后的FCKeditor_2.6.6.zip 里面的fckeditor文件夹拷贝到当前的项目文件夹里面。我的fckeditorTest项目目录结构如下:
4、配置web.xml。配置文件如下,这就是全部了,其他的不需要再配置,由于SimpleUploaderServle整合到了ConnectorServlet里面,所以文件上传等都不需要再配置。
- <servlet>
- <servlet-name>Connector</servlet-name>
- <servlet-class>
- net.fckeditor.connector.ConnectorServlet
- </servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>Connector</servlet-name>
- <url-pattern>
- /fckeditor/editor/filemanager/connectors/*
- </url-pattern>
- </servlet-mapping>
5、解压FCKeditor-java-demo-2.6.war后,将\WEB-INF\lib\下的所有jar包复制到自己项目下\WEB-INF\lib\中。这一步非常重要,FCKeditor要使用到这些jar文件。
6、在src目录下面建立fckeditor.properties资源文件,在里面写入这么一行:
- connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl
7、测试页面 index.jsp:
- <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
- <%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>FckEditor测试</title>
- </head>
- <body style="text-align: center;">
- <div style="text-align: center;width: 600pt">
- <h2>FckEditor测试</h2>
- <hr>
- <form action="ShowData.jsp" method="post">
- <FCK:editor instanceName="test" height="400pt">
- <jsp:attribute name="value">www.sunchis.com</jsp:attribute>
- </FCK:editor>
- <input type="submit" value="提交"/>
- <input type="reset" value="重置"/>
- </form>
- </div>
- </body>
- </html>
8、显示数据的页面 ShowData.jsp:
- <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
- <html>
- <head>
- <title>FCKeditor - 显示数据</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <%
- request.setCharacterEncoding("UTF-8");
- String data = request.getParameter("test");
- %>
- <body>
- <h1>FCKeditor - 显示数据</h1>
- <hr/><br />
- <%=data%>
- </body>
- </html>
9、测试截图。
10、给FckEditor瘦身
① 删除fckeditor目录下面所有以“_”开头的文件或者文件夹,像"_samples"、"_documentation.html“等;
② 删除fckeditor目录下面除了fckconfig.js、fckpackage.xml fckstyles.xml、fcktemplates.xml外的所有文件,当然要保留editor文件夹;
③ 删除fckeditor/editor/lang目录下面除了en.js、 zh-cn.js外的所有文件;
④ 删除fckeditor\editor\filemanager目录下面的connectors文件夹;
11、项目测试源码下载
下载我已经打包好的war文件,在Eclipse中执行“文件” -> “导入”,选择要导入的文件类型为WAR即可导入到Eclipse工作空间中。