在JSP中配置FCKeditor 2.6.4
Posted on 2009-06-02 17:42 ZhouFeng 閱讀(6149) 評(píng)論(7) 編輯 收藏 所屬分類(lèi): 轉(zhuǎn)載 、CKEditor1.FCKeditor 介紹
FCKeditor 這個(gè)開(kāi)源的HTML 文本編輯器可以讓web 程序擁有如MS Word 這樣強(qiáng)大的編輯功能,.FCKeditor 支持當(dāng)前流行的瀏覽器。
2.準(zhǔn)備工作:
環(huán)境:winddows XP、tomcat6.0、JDK1.6
下載:
1):FCKeditor_2.6.4.zip
地址:http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor_2.6.4.zip
2):fckeditor-java-2.4.1-bin.zip (JAVA支持包)地址http://nchc.dl.sourceforge.net/sourceforge/fckeditor/fckeditor-java-2.4.1-bin.zip
3):slf4j-1.5.2.zip 地址 :http://www.slf4j.org/dist/slf4j-1.5.2.zip
3.安裝:
下面以jsp為例:
分別解壓之后,我們可以得到一個(gè)fckeditor和fckeditor-java-2.4.1兩個(gè)文件夾。fckeditor文件夾下是需要調(diào)用的頁(yè)面和js文件等等,有各種版本,無(wú)所謂啦,我們之需要jsp就夠了。將文件加全部復(fù)制到工程目錄下等待調(diào)用即可。
注意:有點(diǎn)麻煩的是導(dǎo)包的問(wèn)題。我們一共需要5個(gè)包:commons-fileupload-1.2.1.jar,commons-io-1.3.2.jar,fckeditor-java-core-2.4.1.jar,slf4j-api-1.5.6.jar,slf4j-simple-1.5.6.jar或slf4j-jdk14-1.5.6.jar。
上面前四個(gè)包都可以在fckeditor-java-2.4.1文件夾下面找到,但是第五個(gè)卻要另外去找,這點(diǎn)我非常不理解,為什么不放在一起。
如果沒(méi)有的話(huà)編譯時(shí)就會(huì)出現(xiàn)如下錯(cuò)誤信息:
嚴(yán)重: Servlet /fckeditorDemo threw load() exception
java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
當(dāng)然版本或許不同,以上的版本是截止2009-02-4的最新版本。如果想要最新版本,可以在slf4j的官網(wǎng)http://www.slf4j.org/download.html下到。但是要注意,截止到2009-2-4,slf4j官方最新版本是1.5.6,但是fckeditor提供的slf4j-api卻是1.5.2版本,如果兩個(gè)版本不一樣的話(huà),你將會(huì)在控制臺(tái)看到如下的消息:
嚴(yán)重: Servlet /Java threw load() exception
java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class
org.slf4j.LoggerFactory
所以千萬(wàn)要注意版本一致問(wèn)題。如果你實(shí)在覺(jué)得下載很麻煩,那就到這里下載吧:http://www.slf4j.org/download.html
4.配置
1)在工程目錄src/下新建一個(gè)文件fckeditor.properties,添加內(nèi)容:
2)修改web.xml,用來(lái)提供上傳功能支持
今天折騰了一個(gè)下午,終于算是看到點(diǎn)效果了,便記錄在這里,上面的內(nèi)容在網(wǎng)上轉(zhuǎn)了一部分,因?yàn)檎也坏皆某鎏?也就沒(méi)有注明了
FCKeditor 這個(gè)開(kāi)源的HTML 文本編輯器可以讓web 程序擁有如MS Word 這樣強(qiáng)大的編輯功能,.FCKeditor 支持當(dāng)前流行的瀏覽器。
2.準(zhǔn)備工作:
環(huán)境:winddows XP、tomcat6.0、JDK1.6
下載:
1):FCKeditor_2.6.4.zip
地址:http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor_2.6.4.zip
2):fckeditor-java-2.4.1-bin.zip (JAVA支持包)地址http://nchc.dl.sourceforge.net/sourceforge/fckeditor/fckeditor-java-2.4.1-bin.zip
3):slf4j-1.5.2.zip 地址 :http://www.slf4j.org/dist/slf4j-1.5.2.zip
3.安裝:
下面以jsp為例:
分別解壓之后,我們可以得到一個(gè)fckeditor和fckeditor-java-2.4.1兩個(gè)文件夾。fckeditor文件夾下是需要調(diào)用的頁(yè)面和js文件等等,有各種版本,無(wú)所謂啦,我們之需要jsp就夠了。將文件加全部復(fù)制到工程目錄下等待調(diào)用即可。
注意:有點(diǎn)麻煩的是導(dǎo)包的問(wèn)題。我們一共需要5個(gè)包:commons-fileupload-1.2.1.jar,commons-io-1.3.2.jar,fckeditor-java-core-2.4.1.jar,slf4j-api-1.5.6.jar,slf4j-simple-1.5.6.jar或slf4j-jdk14-1.5.6.jar。
上面前四個(gè)包都可以在fckeditor-java-2.4.1文件夾下面找到,但是第五個(gè)卻要另外去找,這點(diǎn)我非常不理解,為什么不放在一起。
如果沒(méi)有的話(huà)編譯時(shí)就會(huì)出現(xiàn)如下錯(cuò)誤信息:
嚴(yán)重: Servlet /fckeditorDemo threw load() exception
java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
當(dāng)然版本或許不同,以上的版本是截止2009-02-4的最新版本。如果想要最新版本,可以在slf4j的官網(wǎng)http://www.slf4j.org/download.html下到。但是要注意,截止到2009-2-4,slf4j官方最新版本是1.5.6,但是fckeditor提供的slf4j-api卻是1.5.2版本,如果兩個(gè)版本不一樣的話(huà),你將會(huì)在控制臺(tái)看到如下的消息:
嚴(yán)重: Servlet /Java threw load() exception
java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class
org.slf4j.LoggerFactory
所以千萬(wàn)要注意版本一致問(wèn)題。如果你實(shí)在覺(jué)得下載很麻煩,那就到這里下載吧:http://www.slf4j.org/download.html
4.配置
1)在工程目錄src/下新建一個(gè)文件fckeditor.properties,添加內(nèi)容:
connector.userFilesPath=UploadFile
connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl
其中第一行為重新定義上傳的文件夾,默認(rèn)文件夾為userfile,保存即可。connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl
2)修改web.xml,用來(lái)提供上傳功能支持
<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.應(yīng)用,建立一JSP文件如下<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>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String content=request.getParameter("edt1");
if (content != null) {
content = content.replaceAll("\r\n", "");
content = content.replaceAll("\r", "");
content = content.replaceAll("\n", "");
content = content.replaceAll("\"", "'");
}else{
content = "";
}
//下面是處理中文內(nèi)容的編碼轉(zhuǎn)換
content = new String(content.getBytes("iso8859-1"),"utf-8");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>FCKEditor 測(cè)試</title>
</head>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<body>
This is my JSP page. <br>
<form method="post" name="frm1">
<script type="text/javascript">
var oFCKeditor = new FCKeditor("edt1");
oFCKeditor.BasePath = "fckeditor/";
oFCKeditor.Height='400';
oFCKeditor.Value="<%=content%>";
oFCKeditor.Create();
</script>
<input type="submit" value="提交">
</form>
<hr>
<%=content%>
</body>
</html>
啟動(dòng)服務(wù)器,用瀏覽器訪問(wèn)即可看到結(jié)果<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String content=request.getParameter("edt1");
if (content != null) {
content = content.replaceAll("\r\n", "");
content = content.replaceAll("\r", "");
content = content.replaceAll("\n", "");
content = content.replaceAll("\"", "'");
}else{
content = "";
}
//下面是處理中文內(nèi)容的編碼轉(zhuǎn)換
content = new String(content.getBytes("iso8859-1"),"utf-8");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>FCKEditor 測(cè)試</title>
</head>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<body>
This is my JSP page. <br>
<form method="post" name="frm1">
<script type="text/javascript">
var oFCKeditor = new FCKeditor("edt1");
oFCKeditor.BasePath = "fckeditor/";
oFCKeditor.Height='400';
oFCKeditor.Value="<%=content%>";
oFCKeditor.Create();
</script>
<input type="submit" value="提交">
</form>
<hr>
<%=content%>
</body>
</html>
今天折騰了一個(gè)下午,終于算是看到點(diǎn)效果了,便記錄在這里,上面的內(nèi)容在網(wǎng)上轉(zhuǎn)了一部分,因?yàn)檎也坏皆某鎏?也就沒(méi)有注明了