FCKeditor是一個專門使用在網頁上屬於開放源代碼的所見即所得文字編輯器。它志於輕量化,不需要太複雜的安裝步驟即可使用。它可和PHP、JavaScript、ASP、ASP.NET、ColdFusion、Java、以及ABAP等不同的編程語言相結合。“FCKeditor”名稱中的“FCK” 是這個編輯器的作者的名字Frederico Caldeira Knabben的縮寫。
FCKeditor 相容於絕大部分的網頁瀏覽器,像是 : Internet Explorer 5.5+ (Windows)、Mozilla
Firefox 1.0+、Mozilla 1.3+ 、Netscape 7+以及Opera瀏覽器。
FCKeditor 的安裝非常容易!最新版本可以在這裏下載!所見即所得編輯器是很容易使用的工具!
下面我就簡單介紹一下FCKeditor在java工程中的使用。
1、下載FCKeditor相關文件
FCKeditor官方下載地址如下:http://ckeditor.com/download
這裏說明一點,如果在官網上下載,需要同時下載FCKeditor和FCKeditor for java 兩個壓縮包。官方的壓縮包很完整,包括示例、使用文檔等較爲全備的附屬物。直接使用需要手動去刪除這些,當然你也可以不去刪除,但對於一個網站來說的確有些過大。所以一般的建議是進行削減瘦身。所以我建議下面的做法,從網上下載fckeditor-java-demo-2.5.war,這個我會在附件中給出。後面的步驟也是根據這個demo來將FCKeditor添加到工程的。
2、將war包拷貝到Tomcat的webapps目錄下,啓動tomcat後,war將自動被解壓並將這個demo工程發佈。
將demo中的fckeditor文件夾拷貝到你所在工程的web目錄下。
將所需的jar拷貝到工程。
將fckeditor.properties拷貝到工程。
3、配置web.xml,引入fckeditor
<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>
4、在頁面中使用FCKeditor
在頁面頭部分引入FCK標籤
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
使用FCKeditor
<FCK:editor instanceName="news.newsContent" width="100%" height="350px" value="${news.newsContent }" > </FCK:editor>