示例一
一、准备工作
在http://www.fckeditor.net/download下载FCKeditor.java和FCKeditor
二、配置测试应用
1.在eclipse下,new webproject建立FCKeditortest应用,
2.在FCKeditortest根目录下,即webRoot目录下,建立文件夹fckeditor,该文件夹存放所有FCKeditor相关文件。
3.将FCKeditor解压后,web/WEB-INF目录下的web.xml文件拷贝到步骤1新建的FCKeditortest应用的WEB-INF目录下.web.xml文件里有关于FCKeditor的配置,代码如下:
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>
com.fredck.FCKeditor.connector.ConnectorServlet
</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/fckeditor/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>
<param-value>/fckeditor/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>true</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>
/fckeditor/editor/filemanager/browser/default/connectors/jsp/connector
</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SimpleUploader</servlet-name>
<url-pattern>
/fckeditor/editor/filemanager/upload/simpleuploader
</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/FCKeditor</taglib-uri>
<taglib-location>/WEB-INF/FCKeditor.tld</taglib-location>
</taglib>
4.将FCKeditor.java解压文件夹下的editor目录拷贝到步骤1建立的fckeditor目录下,可以将editor下的_source目录删除
5.将FCKeditor.java解压文件夹下的fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml四个文件拷贝到步骤1建立的fckeditor目录下
6.将FCKeditor解压文件夹下的web/WEB-INF/lib下的jar文件拷贝到步骤1建立的FCKeditortest应用的lib下
7.插入图片和图片文件上传功能,还会报错,需要将xalan.jar、serializer.jar拷贝到lib目录下,那两个jar文件jboss应用服务器的lib\endorsed目录下能找到.
8.在fckeditor目录下,建立userfiles/Image文件夹,存放上传图片文件用。
9.将FCKeditor解压文件夹下的src/FCKeditor.tld拷贝到应用的WEB-INF目录下
10.按如下方法建立测试页面,即可
三、fckeditor用法
1.fckeditor的自定义标签:(必须加头文件<%@ taglib uri="/FCKeditor" prefix="FCK" %>) 代码如下:
<form action="FckAction.do" method="post" target="_blank">
<textarea id="content" name="content"
style="display: none"><%=request.getAttribute("content") %></textarea>
<input type="hidden" id='page' name='page' value='test1'>
<fck:editor id="content" basePath="/fckeditor_test/fckeditor/"
width="700" height="500" skinPath="/fckeditor_test/fckeditor/editor/skins/silver/"
toolbarSet="Default">
</fck:editor>
<input type="submit" value="Submit" />
</form>
2.script语言(必须引用 脚本文件<script type="text/javascript" src="/FCKeditor/fckeditor.js"></script> )
<form action="FckAction.do" method="post" target="_blank">
<input type="hidden" id='page' name='page' value='test2'>
<table border="0" width="700">
<tr>
<td>
<textarea id="content" name="content"
style="WIDTH: 100%; HEIGHT: 400px"><%=request.getAttribute("content") %></textarea>
<script language="javascript">
var oFCKeditor = new FCKeditor('content') ;
oFCKeditor.BasePath = "/fckeditor_test/fckeditor/" ;
oFCKeditor.Height = 400;
oFCKeditor.ToolbarSet = "Default" ;
oFCKeditor.ReplaceTextarea();
</script>
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
3.FCKeditor API 调用 (必须加头文件<%@ page language="java" import="com.fredck.FCKeditor.*" %> )
<form action="FckAction.do" method="post" target="_blank">
<input type="hidden" id='page' name='page' value='test3'>
<textarea id="content" name="content"
style="display: none"><%=request.getAttribute("content") %></textarea>
<%
FCKeditor oFCKeditor ;
oFCKeditor = new FCKeditor( request, "content" ) ;
oFCKeditor.setBasePath( "/fckeditor_test/fckeditor/" ) ;
oFCKeditor.setWidth("500");
oFCKeditor.setHeight("400");
oFCKeditor.setValue( "input" );
out.println( oFCKeditor.create() ) ;
%>
<input type="submit" value="Submit">
</form>
四、js与fckeditor的交互
//js获得fckeditor输入框内容
function getContent() {
//参数是输入框id
var oEditor = FCKeditorAPI.GetInstance('content') ;
alert(oEditor.GetXHTML(true));
}
//js设置fckeditor输入框内容
function setContent() {
//参数是输入框id
var oEditor = FCKeditorAPI.GetInstance('content') ;
oEditor.SetHTML('新内容');
}
五、修改FCKeditor的字体和字号
字体:fckconfig.js第143行
FCKConfig.FontNames = '宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
字号:fckconfig.js第144行
FCKConfig.FontSizes = '1/5;2/7;3/8;4/9;5/10;6/12;7/14;8/16;9/18;10/20;1/xx-small;2/x-small;3/small;4/medium;5/large;6/x-large;7/xx-large' ;
示例二
一、简介
功能:所见即所得,支持图片和Flash,工具栏可自由配置,使用简单
兼容性:IE 5.5+、Firefox 1.5+、Safari 3.0+、Opera 9.50+、Netscape 7.1+、 Camino 1.0+
成熟度:使用广泛,被Baidu、CSDN等选用
二、下载
官方下载首页:http://www.fckeditor.net/download/,当前版本为2.5.1
需要下载FCKeditor 2.5.1(FCKeditor_2.5.1.zip)和FCKeditor.Java(FCKeditor-2.3.zip)
三、部署
1、FCKeditor_2.5.1.zip解压,将fckeditor文件夹复制到/WebRoot/下
2、FCKeditor-2.3.zip解压,将commons-fileupload.jar和FCKeditor-2.3.jar复制到/WebRoot/WEB-INF/lib/下
3、修改/WebRoot/WEB-INF/web.xml文件,增加以下内容:
4、修改/WebRoot/fckeditor/fckconfig.js,修改部分如下:
注意:
(1) 步骤3、4设置了文件浏览和上传的配置,web.xml中Servlet的<url-pattern>要和fckconfig.js中的URL引用一致;
(2) 本例正常运行的前提是WebRoot被部署为根路径,如果设了虚拟路径会找不到servlet。
四、使用
本例使用最直接的js方式,API和TagLib方式参见FCKeditor-2.3.zip解压后_samples下的例子。
fckdemo.jsp:
五、配置文件fckconfig.js
1、DefaultLanguage:缺省语言,可更改为“zh-cn”
2、自定义工具栏:可修改或增加ToolbarSets,例如:
3、EnterMode和ShiftEnterMode:“回车”和“Shift+回车”的换行行为,注释提示了可选模式
4、EditorAreaCss:编辑区样式文件
5、其他参数(转):
六、自定义样式
工具栏的Style选项,是由fckconfig.js指定的配置文件来产生的:
可修改fckstyles.xml来自定义样式。