这两天我就一直在琢磨如何才能实现在编编辑器的功能,由于家里的网是电信天翼的3G卡,有流量限制,如今也就剩下100M左右的流量了,上网也很费劲,于是狠心的上网找了一大堆的资料,终于实现了这样的功能,确实挺纠结的,这里我先给大家演示基本的搭建,下一篇文章演示在Struts2框架下的搭建。在分享我需要声明一下,这篇文章是参考几个网友提供的资料再加上自己的亲身实现,进行的一些修改,最终分享给大家。
CKEditor是新一代的FCKeditor,是一个重新开发的版本。CKEditor是全球最优秀的网页在线文字编辑器之一,因其惊人的性能与可扩展性而广泛的被运用于各大网站。
CKFinder 也是 CK 系列的产品之一,它有两个功能:上传文件、浏览文件。一般来说,它是集成在 CKEditor 或 FCKEditor 中,以便在编辑器中插入超链接或图像时可以直接上传,也可通过浏览直接插入编辑器中。并且 CKFinder 提供了权限接口,以避免没有权限的人去上传文件。CKFinder 是收费的;如果不购买 license,那么就是处于演示模式下使用,禁止用于商业用途。
3、将ckfinder_java_2.3.zip解压,然后将CKFinderJava.war解压后,将WEB-INF里面的lib下面所有的 jar包拷贝至web项目的lib下,将ckfinder\_sources\CKFinder for Java\WebApp\src\main\webapp下的ckfinder文件夹拷贝至web工程下,与ckeditor保持同级,将其下的WEB- INF下面的config.xml文件拷贝至web项目的WEB-INF下,并根据自己的项目稍作调整即可,如下:
<config>
<enabled>true</enabled>
<baseDir></baseDir>
<baseURL>/Software_Site/View/UploadFiles/</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>0</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>0</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>0</maxSize>
<allowedExtensions>swf,flv</allowedExtensions>
<deniedExtensions></deniedExtensions>
</type>
</types>
<accessControls>
<accessControl>
<role>*</role>
<resourceType>*</resourceType>
<folder>/</folder>
<folderView>true</folderView>
<folderCreate>true</folderCreate>
<folderRename>true</folderRename>
<folderDelete>true</folderDelete>
<fileView>true</fileView>
<fileUpload>true</fileUpload>
<fileRename>true</fileRename>
<fileDelete>true</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>
4、然后在web.xml下添加上传用的配置如下:
<!-- ckfinder开始 --> <servlet> <servlet-name>ConnectorServlet</servlet-name> <servlet-class>com.ckfinder.connector.ConnectorServlet</servlet-class> <init-param> <param-name>XMLConfig</param-name> <param-value>/WEB-INF/config.xml</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> /ckfinder/core/connector/java/connector.java </url-pattern> </servlet-mapping> <session-config> <session-timeout>10</session-timeout> </session-config> <!--ckeditor结束 -->5、然后修改ckeditor下面的config.js,如下:
/* Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.editorConfig = function( config ) { // Define changes to default configuration here. For example: // config.language = 'fr'; // config.uiColor = '#AADC6E'; config.language = 'zh-cn' ; config.skin = 'office2003'; };6、然后就是CKEditor+CKFinder在jsp页面中应用,我这里仅仅演示上传图片的部分:
a、首先在页面的头部加上这两句:
<%@ taglib uri="http://ckeditor.com" prefix="ckeditor"%> <%@ taglib uri="http://ckfinder.com" prefix="ckfinder"%>b、其次是在<head></head>标签之间加入这两句:
<script type="text/javascript" src="/Software_Site/ckeditor/ckeditor.js"> <script type="text/javascript" src="/Software_Site/ckfinder/ckfinder.js">c、实现部分如下:
<textarea rows="15" cols="60" id="onlineArticle.text" name="onlineArticle.text"></textarea> <ckfinder:setupCKEditor basePath="/Software_Site/ckfinder/" editor="onlineArticle.text" /> <ckeditor:replace replace="onlineArticle.text" basePath="/Software_Site/ckeditor/" />
OK!到这里就可以实现了。
参考网址:
lpz283929516网友:http://blog.csdn.net/lpz283929516/article/details/8286383
jian85733547网友:http://blog.csdn.net/jian85733547/article/details/5911866