posts - 2, comments - 27, trackbacks - 0, articles - 60
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          在JSP中配置FCKeditor 2.6.4

          Posted on 2009-06-02 17:42 ZhouFeng 閱讀(6149) 評(píng)論(7)  編輯  收藏 所屬分類(lèi): 轉(zhuǎn)載CKEditor
          1.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)容:
          connector.userFilesPath=UploadFile
          connector.userActionImpl
          =net.fckeditor.requestcycle.impl.UserActionImpl
          其中第一行為重新定義上傳的文件夾,默認(rèn)文件夾為userfile,保存即可。
          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文件如下
          <%@ 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é)果

          今天折騰了一個(gè)下午,終于算是看到點(diǎn)效果了,便記錄在這里,上面的內(nèi)容在網(wǎng)上轉(zhuǎn)了一部分,因?yàn)檎也坏皆某鎏?也就沒(méi)有注明了

          評(píng)論

          # re: 在JSP中配置FCKeditor 2.6.4  回復(fù)  更多評(píng)論   

          2009-08-21 03:37 by lzg
          slf4j-simple-1.5.6.jar---------
          先用1.5.2的如你所說(shuō)報(bào)錯(cuò)了。
          又去下,只看見(jiàn)有1.5.8的版本。
          剛好,換上去可以用。
          半夜研究了好半天,
          本來(lái)說(shuō)這次失敗也睡覺(jué)去的。
          —_—#

          竟然成功了,但是跟我之前網(wǎng)上看到的方法有好大的差異,
          這點(diǎn)有點(diǎn)困惑。
          謝謝你的分享。

          # re: 在JSP中配置FCKeditor 2.6.4  回復(fù)  更多評(píng)論   

          2009-08-23 21:38 by 李凱
          呵呵,謝謝

          # re: 在JSP中配置FCKeditor 2.6.4  回復(fù)  更多評(píng)論   

          2009-12-01 10:37 by dubi
          超正確的文章,謝謝

          # re: 在JSP中配置FCKeditor 2.6.4  回復(fù)  更多評(píng)論   

          2009-12-09 19:51 by 笑話(huà)論壇
          我用是的2.6.5的。
          測(cè)試是沒(méi)出問(wèn)題,只是中文用不了
          會(huì)出現(xiàn)亂碼

          # re: 在JSP中配置FCKeditor 2.6.4  回復(fù)  更多評(píng)論   

          2009-12-09 20:37 by 笑話(huà)論壇
          自己再配置一篇,竟然圖片上傳不了

          # re: 在JSP中配置FCKeditor 2.6.4[未登錄](méi)  回復(fù)  更多評(píng)論   

          2010-03-10 15:09 by aaa
          connector.userFilesPath=UploadFile
          這個(gè)地方應(yīng)該改為:connector.userFilesPath=/UploadFile

          # re: 在JSP中配置FCKeditor 2.6.4[未登錄](méi)  回復(fù)  更多評(píng)論   

          2015-04-06 15:14 by ff
          嘻嘻嘻嘻嘻嘻想
          主站蜘蛛池模板: 大邑县| 长子县| 临安市| 廉江市| 平凉市| 大余县| 桐柏县| 东丽区| 安阳县| 兴宁市| 福贡县| 陕西省| 大城县| 新晃| 潼南县| 株洲县| 灌云县| 伊通| 巨野县| 新晃| 永福县| 山西省| 新宁县| 疏附县| 邓州市| 合阳县| 东丰县| 舞阳县| 韩城市| 邯郸县| 安图县| 漳浦县| 江安县| 富源县| 扶风县| 来宾市| 田阳县| 建始县| 封丘县| 图们市| 诸暨市|