FCKeditor官司方网址:http://www.fckeditor.net/
FCKeditor在线DEMO:http://www.fckeditor.net/demo
FCKeditor下载直址:http://www.fckeditor.net/download (该版本为2.3.2),最新版已经是2.4了。
2.FCKeditor.java介绍
不能直接在JSP项目中使用,需要FCKeditor.java库的支持。
FCKeditor.java是针对对JAVA中使用FCKeditor由Simone Chiaretta开发的FCKeditor的JAVA实现。
下载地址:http://www.fckeditor.net/download (最近版本为2.3)
3.在JAVA项目中使用FCKeditor在线编辑器
开发环境:JDK5.0 +<!--[if !supportLists]--> Eclipse3.2.1 + WTP1.5.2
(1)新建一个WEB工程:
(2) 解压 FCKeditor_2.3.2.zip包,将其中的 edit 文件夹到项目中的 WebRoot 目录
(3) 解压 FCKeditor_2.3.2.zip 包,将其中的 fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml 文件夹到项目中的 WebRoot 目录
(4) 解压 FCKeditor.java-2.3.zip 包,将其中的 \web\WEB-INF\lib 下的两个 jar 文件到项目的 WebRoot\WEB-INF\lib 目录
(5) 解压 FCKeditor.java-2.3.zip 包,将其中的 \src 下的 FCKeditor.tld 文件到项目的 WebContent\WEB-INF 目录
(6) 删除 WebContent\edit 目录下的 _source 文件夹(以“_”开始的文件,在项目中无用)
完成后的目录结构下如:说明:图中的input.jsp和display.jsp两个是我写的测试集成FCKeditor的JSP文件。
UserFiles是FCKeditor上传文件的文件夹。
修改WebContent/WEB-INF/web.xml文件,加入FCKeditor的配置信息,如下:
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>FCKeditor</display-name> <servlet> <servlet-name>Connector</servlet-name> <servlet-class> com.fredck.FCKeditor.connector.ConnectorServlet </servlet-class> <init-param> <param-name>baseDir</param-name> <!-- 此为文件浏览路径 --> <param-value>/UserFiles/</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>SimpleUploader</servlet-name> <servlet-class> com.fredck.FCKeditor.uploader.SimpleUploaderServlet </servlet-class> <init-param> <param-name>baseDir</param-name> <!-- 此为文件上传路径,需要在WebRoot 目录下新建 UserFiles 文件夹 --> <!-- 根据文件的类型还需要新建相关的文件夹 Image、Flash --> <param-value>/UserFiles/</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <init-param> <!-- 此参数为是否开启上传功能 --> <param-name>enabled</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>AllowedExtensionsFile</param-name> <param-value></param-value> </init-param> <init-param> <!-- 此参数为文件过滤,以下的文件类型都不可以上传 --> <param-name>DeniedExtensionsFile</param-name> <param-value> php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi </param-value> </init-param> <init-param> <param-name>AllowedExtensionsImage</param-name> <param-value>jpg|gif|jpeg|png|bmp</param-value> </init-param> <init-param> <param-name>DeniedExtensionsImage</param-name> <param-value></param-value> </init-param> <init-param> <param-name>AllowedExtensionsFlash</param-name> <param-value>swf|fla</param-value> </init-param> <init-param> <param-name>DeniedExtensionsFlash</param-name> <param-value></param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Connector</servlet-name> <url-pattern> /editor/filemanager/browser/default/connectors/jsp/connector </url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>SimpleUploader</servlet-name> <url-pattern> /editor/filemanager/upload/simpleuploader </url-pattern> </servlet-mapping> </web-app>
注:web.xml中已经加入了一些常用配置的说明。
<%...@ page contentType="text/html;charset=UTF-8" language="java"%> <%...@ taglib uri="/WEB-INF/FCKeditor.tld" prefix="fck"%> <html> <head> <title>Test</title> </head> <script type="text/javascript" src="fckeditor.js"></script> <script type="text/javascript">... window.onload = function() ...{ var oFCKeditor = new FCKeditor("testfck"); <!—注意这里 --> oFCKeditor.BasePath = ""; oFCKeditor.ToolbarSet = "Basic"; oFCKeditor.ReplaceTextarea("testfck"); } </script> <body> <FORM action="display.jsp"> <textarea rows="20" cols="20" id="testfck" name="testfck"></textarea> <br> <!—注意这里 --> <hr> <input type="submit" value="提交"></FORM> </body> </html>说明:在JSP中集成FCKeditor有以下几种方式:
<%@ taglib uri=”/WEB-INF/FCKeditor.tld” prefix=”fck” %>
<fck:editor id="testfck" <!—注意这里 --> basePath="/FCKeditor/" height="60%" skinPath="/FCKeditor/editor/skins/default/" toolbarSet="Default" imageBrowserURL="/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector" linkBrowserURL="/FCKeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" flashBrowserURL="/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector" imageUploadURL="/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Image" linkUploadURL="/FCKeditor/editor/filemanager/upload/simpleuploader?Type=File" flashUploadURL="/FCKeditor/editor/filemanager/upload/simpleuploader?Type=Flash"> </fck:editor>(10) 新建display.jsp文件,这个文件比较简单,只是简单的显示从FCKeditor在线编辑器传递过来的内容,如下:
<%=request.getParameter("testfck")%>注意这里的getParameter(“testfck”),这个”testfck”就是在input.jsp中设置的id。
<?xml version="1.0" encoding="utf8"?> <Styles> <Style name="MyImage" element="img"> <Attribute name=" style " value="padding:5px" /> <Attribute name=" border " value="2" /> </Style> <Style name=" Italic " element="em" /> <Style name=" Title " element="span"> <Attribute name=" class " value="Title" /> </Style> <Style name=" TitleH3 " element="h3" /> </Styles>每一个STYLE 标记定义一种样式,NAME 是显示在下拉列表中的样式名,ELEMENT 属性指