FCKeditor_教程

其调用方式主要有两种:

1.      通过javascript调用

2.      在jsp中通过自定义标签调用

通过javascript调用

安装:将FCKeditor_2.6.6解压后拷到对应的Web目录下

方法一

<html>

    <head>

       <metahttp-equiv="content-type"content="text/html; charset=UTF-8">

       <title>通过javascript调用FCKeditor</title>

       <scripttype="text/javascript"src="fckeditor/fckeditor.js"></script>

    </head>

    <body>

       This is myHTML page.

       <br>

       <scripttype="text/javascript">

           var oFCKeditor=newFCKeditor('FCKeditor1');

           oFCKeditor.BasePath="fckeditor/";

           oFCKeditor.Create();

       </script>

    </body>

</html>

 

方法二

<html>

    <head>

       <metahttp-equiv="content-type"content="text/html;charset=UTF-8">

       <title>通过javascript调用FCKeditor</title>

<scripttype="text/javascript"src="fckeditor/fckeditor.js"></script>

       <scripttype="text/javascript">

           window.οnlοad=function()

                         {  var oFCKeditor=new FCKeditor('MyTextarea');

                             oFCKeditor.BasePath="fckeditor/";

                             oFCKeditor.ReplaceTextarea();

                         }

       </script>

    </head>

    <body>

       <textarearows="4" cols="60"id="MyTextarea"name="MyTextarea"/>

    </body>

</html>

 

FCKeditor对象的基本属性

属性名

描述

默认值

Width

宽度

100%

Height

高度

200

Value

编辑器初始化内容

(空字符串)

ToolbarSet

工具条集合的名称(内置有Default和Basic,也可以自己定制)

Default

BasePath

编辑器的基路经

Fckeditor(与具体的安装路径有关)

 

构造器

var FCKeidtor=function(instanceName,width,height,toolbarSet,value)

其中instanceName为编辑器输出的textarea元素的name属性的值,必须指定

其他参数会赋值给同名属性

 

在jsp中通过自定义标签调用

安装:将commons-fileupload-1.2.1.jar 

commons-io-1.3.2.jar  

fckeditor-java-core-2.6.jar

imageinfo-1.9.jar

slf4j-api-1.5.8.jar 

slf4j-simple-1.5.8.jar    拷到对应的项目工程中

同时将FCKeditor_2.6.6解压后拷到对应的Web目录下

页面调用

<%@ pagelanguage="java" pageEncoding="UTF-8"%>

<%@ taglibprefix="FCK"uri="http://java.fckeditor.net"%>

<!DOCTYPEHTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <title>通过jsp标签调用FCKeditor</title>

  </head>

  <body>

    This is my JSP page. <br>

    <FCK:editorinstanceName="myFCKeditor"basePath="/fckeditor/"value=""></FCK:editor>

  </body>

</html>

 

basePath以“/”开头,并且这个“/”代表当前工程的路径

 

 

FCKeditor的配置 就是修改fckconfig.js文件

方法一:加载新配置文件

FCKConfig.CustomConfigurationsPath=’/myconfig.js’

 

方法二:通过javascript指定

var oFCKeditor=new FCKeditor(“FCKeditor1”);

oFCKeditor.Config[“CustomConfigurationsPath”]=”/myconfig.js”;

oFCKeditor.Create();

 

方法三:直接修改主配置文件对应的项

 

 

配置加载顺序

1加载主配置文件fckconfig.js

2加载自定义的配置文件(如果有),覆盖相同的配置项

3使用对实例的配置覆盖相同的配置项(只对当前实例有效)

 

 

提示:

系统会自动侦测并运用适当的界面语言(默认,可以修改)

     不能删除主配置文件fckconfig.js

        修改配置后要清空浏览器缓存,以免影响结果

        使用UTF-8编码保存配置文件

        FCKConfig.BasePath和调用fckeditor时指定的BasePath(FCKeditor.BasePath)不是同一个,其值也不一样

 

 

一般需要修改的配置

自定义ToolbarSet,去掉一些功能

加上集中常用的字体

修改回车和shift+回车的换行行为

修改编辑区样式文件

更换表情图片

 

 

要使用其文件上传功能应作如下配置:

在web.xml中配置servlet

<servlet>

    <servlet-name>Connector</servlet-name>

    <servlet-class>net.fckeditor.connector.ConnectorServlet</servlet-class>

  </servlet>

  <servlet-mapping>

    <servlet-name>Connector</servlet-name>

<url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>

  </servlet-mapping>

并且新建fckeditor.properties文件写入:

connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl

 

 

FCKeditor与表单的交互只需要通过request.getParameter(“FCKeditroName”); 获取相应的值


1.下载
FCKeditor.java 2.3 (FCKeditot for java)
FCKeditor 2.2 (FCKeditor基本文件) 
2.建立项目:tomcat/webapps/TestFCKeditor.


3.将FCKeditor2.2解压缩,将整个目录FCKeditor复制到项目的根目录下,
目录结构为:tomcat/webapps/TestFCKeditor/FCKeditor
然后将FCKeditor-2.3.zip(java)压缩包中\web\WEB-INF\lib\目录下的两个jar文件拷到项目的\WEB-INF\lib\目录下。把其中的src目录下的FCKeditor.tld文件copy到TestFCKedit/FCKeitor/WEB-INF/下


4.将FCKeditor-2.3.zip压缩包中\web\WEB-INF\目录下的web.xml文件合并到项目的\WEB-INF\目录下的web.xml文件中。


5. 修改合并后的web.xml文件,将名为SimpleUploader的Servlet的enabled参数值改为true,
以允许上传功能,Connector Servlet的baseDir参数值用于设置上传文件存放的位置。
添加标签定义:
<taglib>
<taglib-uri>/TestFCKeditor</taglib-uri>
<taglib-location>/WEB-INF/FCKeditor.tld</taglib-location>
</taglib>




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。


7.进入skin文件夹,如果你想使用fckeditor默认的这种奶黄色,
那就把除了default文件夹外的另两个文件夹直接删除.


8.删除/FCKeditor/目录下除fckconfig.js, fckeditor.js, fckstyles.xml, fcktemplates.xml四个文件以外的所有文件 
删除目录/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' ;


7、添加页面


<%@ page language="java" import="com.fredck.FCKeditor.*" %>
<%@ taglib uri="/WEB-INF/tlds/FCKeditor.tld" prefix="FCK" %>
<script type="text/javascript" src="FCKeditor/fckeditor.js"></script>


<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 = "FCKeditor/" ;
oFCKeditor.Height = 400;
oFCKeditor.ToolbarSet = "Default" ; 
oFCKeditor.ReplaceTextarea();
</script>
<input type="submit" value="Submit">
</td></tr></table>
</form>


编辑web.xml 文集 添加 如下片断


<servlet>
   <servlet-name>SimpleUploader</servlet-name>
   <servlet-class>com.fredck.FCKeditor.uploader.SimpleUploaderServlet</servlet-class>
   <init-param>
    <param-name>baseDir</param-name>
    <param-value>/UserFiles/</param-value>
   </init-param>
   <init-param>
    <param-name>debug</param-name>
    <param-value>true</param-value>
   </init-param>
   <init-param>
    <param-name>enabled</param-name>
    <param-value>false</param-value>
   </init-param>
   <init-param>
    <param-name>AllowedExtensionsFile</param-name>
    <param-value></param-value>
   </init-param>
   <init-param>
    <param-name>DeniedExtensionsFile</param-name>
    <param-value>php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi</param-value>
   </init-param>
   <init-param>
    <param-name>AllowedExtensionsImage</param-name>
    <param-value>jpg|gif|jpeg|png|bmp</param-value>
   </init-param>
   <init-param>
    <param-name>DeniedExtensionsImage</param-name>
    <param-value></param-value>
   </init-param>
   <init-param>
    <param-name>AllowedExtensionsFlash</param-name>
    <param-value>swf|fla</param-value>
   </init-param>
   <init-param>
    <param-name>DeniedExtensionsFlash</param-name>
    <param-value></param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
</servlet>


   <servlet-mapping>
     <servlet-name>Connector</servlet-name>
     <url-pattern>/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
   </servlet-mapping>
  
   <servlet-mapping>
     <servlet-name>SimpleUploader</servlet-name>
     <url-pattern>/FCKeditor/editor/filemanager/upload/simpleuploader</url-pattern>
   </servlet-mapping>  






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





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值