一,、相信很多人都用過(guò)大名鼎鼎的FckEditor,, 最新又出來(lái)了個(gè)ckEditor,, 令人一下子搞不清楚, 到官方網(wǎng)站看看才知道FckEditor在2.6版本之后就改名為ckEditor了,, 在這里特別說(shuō)明一下,, 以免混淆,,因?yàn)榫W(wǎng)上搜出來(lái)的大多都是FckEditor相關(guān)配置的文章,。
二、FckEditor里有java版本的配置,,相信有些同行用過(guò),,支持php、asp.net,、java版本,,現(xiàn)在一下子變?yōu)閏kEditor了。配置簡(jiǎn)單的編輯器很簡(jiǎn)單,,這里不多說(shuō)了,,我想大多數(shù)人都希望能用到編輯器里的瀏覽/插入圖片功能吧, 畢竟一條新聞沒(méi)個(gè)圖片說(shuō)不過(guò)去,。 當(dāng)然我們自己做個(gè)上傳功能,,然后復(fù)制URL地址插入到URL里也是可以的。 但是這樣客戶操作難度太高了,。
三,、這里介紹一下解決辦法,看到有個(gè)哥們的文章說(shuō)ckEditor理把自帶的上傳功能去掉了,, 需要修改config.js文件里的幾個(gè)屬性
config.filebrowserBrowseUrl = '/js/ckfinder/ckfinder.htm';
config.filebrowserImageBrowseUrl = '/js/ckfinder/ckfinder.htm?type=Images';
config.filebrowserFlashBrowseUrl = '/js/ckfinder/ckfinder.htm?type=Flash';
config.filebrowserUploadUrl = '/js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Files';
config.filebrowserImageUploadUrl = '/js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Images';
config.filebrowserFlashUploadUrl = '/js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Flash';
需要自己寫(xiě)這個(gè)上傳附件和瀏覽服務(wù)器文件的方法,, 這哥們還真的自己寫(xiě)了, 遺憾的是只給出部分代碼,。 自己寫(xiě)上傳文件和瀏覽文件夾雖然說(shuō)不是什么難事,, 但難免有些繁瑣費(fèi)時(shí)。
四,、于是自己抱有一點(diǎn)僥幸和偷懶的心理再google了幾下,, 發(fā)現(xiàn)一個(gè)關(guān)鍵字很頻繁出現(xiàn): cdeditor+ckfinder 后面老跟著asp.net php 之類(lèi)的。于是就不服氣滴想,,難道就沒(méi)有支持java的嗎,? ckfinder不是專(zhuān)門(mén)為asp.net量身定做的吧? 于是又仔細(xì)看了看cdeditor的官方網(wǎng)站,, 然后點(diǎn)擊了一下ckfinder鏈接,, 發(fā)現(xiàn)ckfinder已經(jīng)出了多個(gè)語(yǔ)言版本(php、asp.net等)
支持java是在2.0.2版本之后才出的,, 這也就難怪關(guān)于cdeditor3.6.5+ckfinder2.0.2+jsp的配置介紹文章很少了,,
這里方便大家下載我給個(gè)地址:
http:///download
http:///download 注意2.0.2版本以及以上的才支持java (收費(fèi)的)
先上個(gè)效果圖再貼代碼!
點(diǎn)擊插入圖片圖標(biāo)
瀏覽/上傳圖片窗口
整合步驟:(注意紅色字體部分是前后相呼應(yīng)的)
1 下載的ckeditor-java-3.6.2.rar和ckfinder_java_2.0.2.zip解壓,, jsp頭部引入兩個(gè)頭文件
<script type="text/javascript" src="${base}/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="${base}/js/ckfinder/ckfinder.js"></script>
2 在web.xml里添加,, 注意ckfinder版本是2.0.2 如果超過(guò)這版本,,servlet的類(lèi)名不一樣小心!
- <span style="font-size:16px;"> <!-- ckeditor和ckfinder整合上傳圖片 開(kāi)始 -->
- <servlet>
- <servlet-name>ConnectorServlet</servlet-name>
- <servlet-class><span style="color:#ff0000;">com.ckfinder.connector.ConnectorServlet</span></servlet-class>
- <init-param>
- <param-name>XMLConfig</param-name>
- <param-value>/WEB-INF/<span style="color:#ff0000;">ckfinder-config.xml</span></param-value>
- </init-param>
- <init-param>
- <param-name>debug</param-name>
- <param-value>false</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>ConnectorServlet</servlet-name>
- <url-pattern>
- <span style="color:#ff0000;">/js/ckfinder/core/connector/java/connector.java</span>
- </url-pattern>
- </servlet-mapping>
- <!-- ckeditor和ckfinder整合上傳圖片 結(jié)束 --></span>
3 在建立文件WEB-INF/ckfinder-config.xml 內(nèi)容如下( 紅色的 upload/ckfinder/代表工程里的路徑,,可以對(duì)照eclipse截圖
- <span style="font-size:18px;"><config>
- <enabled>true</enabled>
- <baseDir></baseDir>
- <baseURL><span style="color:#ff0000;"></span><span style="color:#ff0000;">upload/ckfinder/</span></baseURL>
- <licenseKey></licenseKey>
- <licenseName></licenseName>
- <imgWidth>1600</imgWidth>
- <imgHeight>1200</imgHeight>
- <imgQuality>80</imgQuality>
- <uriEncoding>UTF-8</uriEncoding>
- <forceASCII>false</forceASCII>
- <userRoleSessionVar>CKFinder_UserRole</userRoleSessionVar>
- <checkDoubleExtension>true</checkDoubleExtension>
- <checkSizeAfterScaling>true</checkSizeAfterScaling>
- <secureImageUploads>true</secureImageUploads>
- <htmlExtensions>html,htm,xml,js</htmlExtensions>
- <hideFolders>
- <folder>.svn</folder>
- <folder>CVS</folder>
- </hideFolders>
- <hideFiles>
- <file>.*</file>
- </hideFiles>
- <defaultResourceTypes></defaultResourceTypes>
- <types>
- <type name="Files">
- <url>%BASE_URL%files/</url>
- <directory>%BASE_DIR%files</directory>
- <maxSize>10m</maxSize>
- <allowedExtensions>7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip
- </allowedExtensions>
- <deniedExtensions></deniedExtensions>
- </type>
- <type name="Images">
- <url>%BASE_URL%images/</url>
- <directory>%BASE_DIR%images</directory>
- <maxSize>2m</maxSize>
- <allowedExtensions>bmp,gif,jpeg,jpg,png</allowedExtensions>
- <deniedExtensions></deniedExtensions>
- </type>
- <type name="Flash">
- <url>%BASE_URL%flash/</url>
- <directory>%BASE_DIR%flash</directory>
- <maxSize>20m</maxSize>
- <allowedExtensions>swf,flv</allowedExtensions>
- <deniedExtensions></deniedExtensions>
- </type>
- </types>
- <accessControls>
- <accessControl>
- <role>*</role>
- <resourceType>*</resourceType>
- <folder>/</folder>
- <folderView>true</folderView>
- <folderCreate>true</folderCreate>
- <folderRename>false</folderRename>
- <folderDelete>false</folderDelete>
- <fileView>true</fileView>
- <fileUpload>true</fileUpload>
- <fileRename>false</fileRename>
- <fileDelete>false</fileDelete>
- </accessControl>
- </accessControls>
- <thumbs>
- <enabled>true</enabled>
- <url>%BASE_URL%_thumbs/</url>
- <directory>%BASE_DIR%_thumbs</directory>
- <directAccess>false</directAccess>
- <maxHeight>100</maxHeight>
- <maxWidth>100</maxWidth>
- <quality>80</quality>
- </thumbs>
- <plugins>
- <plugin>
- <name>imageresize</name>
- <class>com.ckfinder.connector.plugins.ImageResize</class>
- <params>
- <param name="smallThumb" value="90x90"></param>
- <param name="mediumThumb" value="120x120"></param>
- <param name="largeThumb" value="180x180"></param>
- </params>
- </plugin>
- <plugin>
- <name>fileeditor</name>
- <class>com.ckfinder.connector.plugins.FileEditor</class>
- <params></params>
- </plugin>
- </plugins>
- <basePathBuilderImpl>com.ckfinder.connector.configuration.ConfigurationPathBuilder</basePathBuilderImpl>
- </config></span>
目錄結(jié)構(gòu)
4 修改/js/ckeditor/config.js里的內(nèi)容如下:
- <span style="font-size:18px;">CKEDITOR.editorConfig = function( config ){
- config.pasteFromWordIgnoreFontFace = true;
- config.language='zh-cn';
- config.uiColor='#AADC6E';
- config.enterMode=CKEDITOR.ENTER_DIV;
- config.shiftEnterMode=CKEDITOR.BR;
- config.skin='office2003';
- config.extraPlugins='autogrow';
- config.resize_maxHeight = 1000;
- config.resize_maxWidth = 960;//改變大小的最大寬度
- config.resize_minHeight = 250; //改變大小的最小高度
- config.resize_minWidth = 750;//改變大小的最小寬度
- config.toolbar = [
- '/',
- ['Preview','Cut','Copy','Paste','PasteFromWord','Print','Undo','Redo','Find','RemoveFormat ','Bold','Italic','Underline','Strike','-','NumberedList','BulletedList'],
- ['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','-','Image','Table','HorizontalRule','Smiley'],
- ['Styles','Format','Font','FontSize'],
- ];
- config.filebrowserBrowseUrl='/js/ckfinder/ckfinder.html';
- config.filebrowserImageBrowseUrl=<span style="color:#ff0000;">'/js/ckfinder/ckfinder.html?type=Images'</span>;
- config.filebrowserFlashBrowseUrl='/js/ckfinder/ckfinder.html?type=Flash';
- config.filebrowserUploadUrl='/js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Files';
- config.filebrowserImageUploadUrl='/<span style="color:#ff0000;">js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Images'</span>;
- config.filebrowserFlashUploadUrl='/js/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Flash';
- config.filebrowserWindowWidth='1000';
- config.filebrowserWindowHeight='700';
- };</span>
5 復(fù)制這幾個(gè)jar包到WEB-INF/lib (前面貼出的那兩個(gè)壓縮文件解壓之后有的
CKFinder-2.0.2.jar
CKFinderPlugin-FileEditor-2.0.2.jar
CKFinderPlugin-ImageResize-2.0.2.jar
Thumbnailator-0.3.3.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
6 在jsp頁(yè)面寫(xiě)代碼:
<script type="text/javascript" src="${base}/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="${base}/js/ckfinder/ckfinder.js"></script>
<textarea id="content" name="content"></textarea>
<script type="text/javascript">
CKEDITOR.replace('content',{height:350});//設(shè)置編輯器高度
</script>
到此就大功告成啦,, 運(yùn)行截圖就是上面那3張! 詳細(xì)的配置屬性請(qǐng)網(wǎng)上參考資料,,都在ckfinder-config.xml里,,可以控制上傳的文件類(lèi)型、大小,、能否刪除,、能否創(chuàng)建子文件夾等。
|