FCKeditor2.4 JSP版使用(轉貼+原創)

1.下載
FCKeditor2.3 (FCKeditot for java)
FCKeditor2.4 (FCKeditor基本文件)
以下是下載地址:
http://www.fckeditor.net/download/default.html

2.建立項目:
建立項目tomcat/webapps/TestFCKeditor.

3.將FCKeditor2.4解壓縮
將FCKeditor2.4解壓縮,將整個目錄FCKeditor複製到項目的根目錄下,並將解壓縮出來的文件夾fckeditor重命名爲FCKeditor
目錄結構爲:tomcat/webapps/TestFCKeditor/FCKeditor
然後將FCKeditor-2.3.zip(java)壓縮包中/web/WEB-INF/lib/目錄下的兩個jar文件拷到項目的/WEB-INF/ lib/目錄下。把其中的src目錄下的FCKeditor.tld文件copy到TestFCKedit/WEB-INF/下

4.合併web.xml:
將FCKeditor-2.3.zip壓縮包中/web/WEB-INF/目錄下的web.xml文件合併到項目的/WEB-INF/目錄下的web.xml文件中。


5. 修改合併後的web.xml文件
修改合併後的web.xml文件,將名爲SimpleUploader的Servlet的enabled參數值改爲true,
以允許上傳功能,Connector Servlet的baseDir參數值用於設置上傳文件存放的位置。
在web.xml最後添加標籤定義:

<taglib>
    <taglib-uri>/TestFCKeditor</taglib-uri>
    <taglib-location>/WEB-INF/FCKeditor.tld</taglib-location>
 </taglib>

現在的web.xml文件沒有<taglib>標籤了,應該直接在jsp文件中使用:<%@ taglib uri="http://fckeditor.net/tags-fckeditor" prefix="FCK" %>



6. 映射:
上面文件中兩個servlet的映射分別爲:/editor/filemanager/browser/default/connectors/jsp/connector
和/editor/filemanager/upload/simpleuploader,需要在兩個映射前面加上/FCKeditor,
即改爲/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector和
/FCKeditor/editor/filemanager/upload/simpleuploader。
這兩個名字根據你放在工程中的FCKeditor文件夾名稱而定。。


7.修改skin文件夾
進入skin文件夾,如果你想使用fckeditor默認的這種奶黃色,
那就把除了default文件夾外的另兩個文件夾直接刪除.(建議不刪除,以後要用到其中的一個文件夾

8.刪除無用文件
刪除/FCKeditor/目錄下除fckconfig.js, fckeditor.js, fckstyles.xml, fcktemplates.xml四個文件以外的所有文件,保留文件夾editor
刪除目錄/editor/_source,
刪除/editor/filemanager/browser/default/connectors/下的所有文件
刪除/editor/filemanager/upload/下的所有文件
刪除/editor/lang/下的除了fcklanguagemanager.js(我下載的沒有這個文件), en.js, zh.js, zh-cn.js四個文件的所有文件

9.修改配置:
打開/FCKeditor/fckconfig.js
修改 FCKConfig.DefaultLanguage = 'zh-cn' ;
把FCKConfig.LinkBrowserURL等的值替換成以下內容:
FCKConfig.LinkBrowserURL
= FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" ;

FCKConfig.ImageBrowserURL
= FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector" ;

FCKConfig.FlashBrowserURL
= FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector" ;

FCKConfig.LinkUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=File' ;
FCKConfig.FlashUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Flash' ;
FCKConfig.ImageUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Image' ;

10.其它
fckconfig.js總配置文件,可用記錄本打開,修改後將文件存爲utf-8 編碼格式。找到:

FCKConfig.TabSpaces = 0 ; 改爲FCKConfig.TabSpaces = 1 ; 即在編輯器域內可以使用Tab鍵。

如果你的編輯器還用在網站前臺的話,比如說用於留言本或是日記回覆時,那就不得不考慮安全了,
在前臺千萬不要使用Default的toolbar,要麼自定義一下功能,要麼就用系統已經定義好的Basic,
也就是基本的toolbar,找到:
FCKConfig.ToolbarSets["Basic"] = [
['Bold','Italic','-','OrderedList','UnorderedList','-',/*'Link',*/'Unlink','-','Style','FontSize','TextColor','BGColor','-',
'Smiley','SpecialChar','Replace','Preview'] ] ;
這是改過的Basic,把圖像功能去掉,把添加鏈接功能去掉,因爲圖像和鏈接和flash和圖像按鈕添加功能都能讓前臺
頁直接訪問和上傳文件, fckeditor還支持編輯域內的鼠標右鍵功能。

FCKConfig.ContextMenu = ['Generic',/*'Link',*/'Anchor',/*'Image',*/'Flash','Select','Textarea','Checkbox','Radio','TextField','HiddenField',
/*'ImageButton',*/'Button','BulletedList','NumberedList','TableCell','Table','Form'] ;

這也是改過的把鼠標右鍵的“鏈接、圖像,FLASH,圖像按鈕”功能都去掉。

  找到: FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
加上幾種我們常用的字體
FCKConfig.FontNames
= '宋體;黑體;隸書;楷體_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;

11.添加文件
添加文件 /TestFCKeditor/test.jsp:
<%@ page language="java" import="com.fredck.FCKeditor.*" %>
<%@ taglib uri="/TestFCKeditor" prefix="FCK" %>
<script type="text/javascript" src="/TestFCKeditor/FCKeditor/fckeditor.js"></script>

<%--
三種方法調用FCKeditor
1.FCKeditor自定義標籤 (必須加頭文件 <%@ taglib uri="/TestFCKeditor" prefix="FCK" %> )
2.script腳本語言調用 (必須引用 腳本文件 <script type="text/javascript" src="/TestFCKeditor/FCKeditor/fckeditor.js"></script> )
3.FCKeditor API 調用 (必須加頭文件 <%@ page language="java" import="com.fredck.FCKeditor.*" %> )
--%>

//標籤調用方式
<%--
<form action="show.jsp" method="post" target="_blank">
<FCK:editor id="content" basePath="/TestFCKeditor/FCKeditor/"
width="700"
height="500"
skinPath="/TestFCKeditor/FCKeditor/editor/skins/silver/"
toolbarSet = "Default"
>
input
</FCK:editor>
<input type="submit" value="Submit">
</form>
--%>

//JS調用方式
<form action="show.jsp" method="post" target="_blank">
<table border="0" width="700"><tr><td>
<textarea id="content" name="content" style="WIDTH: 100%; HEIGHT: 400px">input</textarea>
<script type="text/javascript">
var oFCKeditor = new FCKeditor('content') ;
oFCKeditor.BasePath = "/TestFCKeditor/FCKeditor/" ;
oFCKeditor.Height = 400;
oFCKeditor.ToolbarSet = "Default" ;
oFCKeditor.ReplaceTextarea();
</script>
<input type="submit" value="Submit">
</td></tr></table>
</form>

//FCKeditor API 調用
<%--
<form action="show.jsp" method="post" target="_blank">
<%
FCKeditor oFCKeditor ;
oFCKeditor = new FCKeditor( request, "content" ) ;
oFCKeditor.setBasePath( "/TestFCKeditor/FCKeditor/" ) ;
oFCKeditor.setValue( "input" );
out.println( oFCKeditor.create() ) ;
%>
<br>
<input type="submit" value="Submit">
</form>
--%>

添加文件/TestFCKeditor/show.jsp:
<%
String content = request.getParameter("content");
out.print(content);
%>




12.測試
瀏覽http://localhost:8080/TestFCKeditor/test.jsp


最後注意。。不同的版本 變量名稱可能不一樣。請參考你使用的API文檔

配置選項:

AutoDetectLanguage=true/false 自動檢測語言
BaseHref="" 相對鏈接的基地址
ContentLangDirection="ltr/rtl" 默認文字方向
ContextMenu=字符串數組,右鍵菜單的內容
CustomConfigurationsPath="" 自定義配置文件路徑和名稱
Debug=true/false 是否開啓調試功能,這樣,當調用FCKDebug.Output()時,會在調試窗中輸出內容
DefaultLanguage="" 缺省語言
EditorAreaCss="" 編輯區的樣式表文件
EnableSourceXHTML=true/false 爲TRUE時,當由可視化界面切換到代碼頁時,把HTML處理成XHTML
EnableXHTML=true/false 是否允許使用XHTML取代HTML
FillEmptyBlocks=true/false 使用這個功能,可以將空的塊級元素用空格來替代
FontColors="" 設置顯示顏色拾取器時文字顏色列表
FontFormats="" 設置顯示在文字格式列表中的命名
FontNames="" 字體列表中的字體名
FontSizes="" 字體大小中的字號列表
ForcePasteAsPlainText=true/false 強制粘貼爲純文本
ForceSimpleAmpersand=true/false 是否不把&符號轉換爲XML實體
FormatIndentator="" 當在源碼格式下縮進代碼使用的字符
FormatOutput=true/false 當輸出內容時是否自動格式化代碼
FormatSource=true/false 在切換到代碼視圖時是否自動格式化代碼
FullPage=true/false 是否允許編輯整個HTML文件,還是僅允許編輯BODY間的內容
GeckoUseSPAN=true/false 是否允許SPAN標記代替B,I,U標記
IeSpellDownloadUrl=""下載拼寫檢查器的網址
ImageBrowser=true/false 是否允許瀏覽服務器功能
ImageBrowserURL="" 瀏覽服務器時運行的URL
ImageBrowserWindowHeight="" 圖像瀏覽器窗口高度
ImageBrowserWindowWidth="" 圖像瀏覽器窗口寬度
LinkBrowser=true/false 是否允許在插入鏈接時瀏覽服務器
LinkBrowserURL="" 插入鏈接時瀏覽服務器的URL
LinkBrowserWindowHeight=""鏈接目標瀏覽器窗口高度
LinkBrowserWindowWidth=""鏈接目標瀏覽器窗口寬度
Plugins=object 註冊插件
PluginsPath="" 插件文件夾
ShowBorders=true/false 合併邊框
SkinPath="" 皮膚文件夾位置
SmileyColumns=12 圖符窗列數
SmileyImages=字符數組 圖符窗中圖片文件名數組
SmileyPath="" 圖符文件夾路徑
SmileyWindowHeight 圖符窗口高度
SmileyWindowWidth 圖符窗口寬度
SpellChecker="ieSpell/Spellerpages" 設置拼寫檢查器
StartupFocus=true/false 開啓時FOCUS到編輯器
StylesXmlPath="" 設置定義CSS樣式列表的XML文件的位置
TabSpaces=4 TAB鍵產生的空格字符數
ToolBarCanCollapse=true/false 是否允許展開/摺疊工具欄
ToolbarSets=object 允許使用TOOLBAR集合
ToolbarStartExpanded=true/false 開啓是TOOLBAR是否展開
UseBROnCarriageReturn=true/false 當回車時是產生BR標記還是P或者DIV標記

解決上傳亂碼:
在SimpleUploaderServlet.java和ConnectorServlet.java兩個文件裏找到
DiskFileUpload upload = new DiskFileUpload();
分別在其後加入 upload.setHeaderEncoding("utf-8");
這樣解決了文件上傳的中文亂碼問題.
但是在控制檯顯示的中文內容還是亂碼,但是沒關係,我們沒必要去看控制檯下的中文

----------------------------------------------------------------another
FCKeditor2.4.2 Java版使用說明
下載地址以及基本配置請參考:http://hi.baidu.com/wain19/blog/item/c33fb0fab74f24dfb48f312d.html

我的開發環境是ubuntu7.04, 系統默認編碼是utf-8,
期間,本人遇到了下面這些問題:

問題一:XML request error: Internel Server Error(500)

出現錯誤的地方是在:點插入圖片,點Browse按鈕的時候:
XML request error: Internel Server Error(500)

找資料:http://lamono.javaeye.com/blog/49135
拷貝xalan.jar和serialize.jar到/WEB-INF/lib,問題解決。

FCKeditor-java沒有很好的解決中文問題。需要我們修改它的源代碼後重新編譯打包。打包過程如下:
1。 新建一個web工程名字爲FCKeditor-java-2.3,然後把FCKeditor-2.3-java.zip解壓縮後的代碼拷貝到工程目錄下。
2。如果是用的Eclipse,使用快捷鍵Ctrl+Shift+R
在SimpleUploaderServlet.java和ConnectorServlet.java兩個文件裏找到
DiskFileUpload upload = new DiskFileUpload();
分別在其後加入 upload.setHeaderEncoding("utf-8");
現在如果直接運行ant任務,會報下面的錯誤:
taskdef class org.apache.catalina.ant.DeployTask cannot be found

3。 把tomcat安裝目錄下/server/lib中的catalina-ant.jar拷貝到/WEB-INF/lib目錄 下。
4。 打開build.xml
找到
<property name="catalina.home"
修改成你自己的tomcat安裝目錄
<property name="catalina.home"         value="/home/uniquejava/tool/tomcat5028/"/>
找到
<taskdef name="deploy"
修改成如下內容
     <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask">
        <classpath refid="compile.classpath">
        </classpath>
    </taskdef>
    <taskdef name="list" classname="org.apache.catalina.ant.ListTask">
        <classpath refid="compile.classpath">
        </classpath>
    </taskdef>
    <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
        <classpath refid="compile.classpath">
        </classpath>
    </taskdef>
    <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask">
        <classpath refid="compile.classpath">
        </classpath>
    </taskdef>

運行ant任務dist, 就可以生成新的FCKeditor-2.3.jar包

問題三: 上傳時新建的中文目錄全部亂碼。 雖然上傳到服務器上的文件名正常,但在JSP頁面點下載鏈接時文件名亂碼導致不能正常下載。

查找資料:TOMCAT 鏈接參數有中文時,亂碼解決方法
http://hi.baidu.com/jadestone/blog/item/7564deefc9192d36acafd5be.html
修改tomcat-home/conf/server.xml
方法一:
在兩處地方加上URIEncoding="utf-8":
    <Connector port="8080"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000"
               disableUploadTimeout="true" URIEncoding="utf-8" />
              
    <Connector port="8009"
               enableLookups="false" redirectPort="8443" debug="0"
               protocol="AJP/1.3" URIEncoding="utf-8" />
              
方法二:
使用useBodyEncodingForURI="true". 這個方法適合你的TOMCAT實例下需要跑多個不同Encoding的程序時。(有點懷疑?!)
<... maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
       enableLookups="false" redirectPort="8443" acceptCount="100"
      connectionTimeout="20000" disableUploadTimeout="true" useBodyEncodingForURI="true" />

     enableLookups="false" redirectPort="8443" protocol="AJP/1.3" useBodyEncodingForURI="true" /

我只試了方法一,問題解決!

這樣, FCKeditor終於可以正常使用了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
=================================================================
以下爲個人原創 http://blog.csdn.net/nickshen3/
怎麼將FCKeditor2.4使用在自己的web中。
1. 在webapps創建test文件夾。webapps/test
2. 將下載的FCKeditor2.3的Java包FCKeditor-2.3.zip解壓縮,並將web文件夾下的兩個文件夾_samples,WEB-INF拷貝到剛纔建立的webapps/test下。再將src文件夾下的FCKeditor.tld拷貝到WEB-INF下。
3. 在webapps/test/下建立文件夾FCKeditor 。
4. 將剛纔下載的 FCKeditor_2.4.3.zip 解壓縮,然後將fckeditor文件夾下的 editor(文件夾),fckconfig.js,fckeditor.js,fckstyles.xml,fcktemplates.xml。四個文件拷貝到剛纔建立的文件夾FCKeditor下。
5.修改test/_samples/jsp/sample02.jsp文件,將原來的
       <FCK:editor id="EditorDefault" basePath="/FCKeditor/"
改爲<FCK:editor id="EditorDefault" basePath="/test/FCKeditor/"。以後使用的時候只需將test換成項目的名稱即可。
另外 :  http://www.blogjava.net/youxia/archive/2007/03/15/104077.html 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章