FCKeditor在线编辑器的使用

1.下载

FCKeditor.java 2.3 (FCKeditot for java)

FCKeditor 2.2 (FCKeditor基本文件)

以下是下载地址:

http://www.fckeditor.net/download/

2.建立项目:

建立项目tomcat/webapps/TestFCKeditor.



3.将FCKeditor2.2解压缩

将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.合并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参数值用于设置上传文件存放的位置。

添加标签定义:

<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文件夹

进入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' ;



11.三种方法调用FCKeditor

(1).FCKeditor自定义标签 (必须加头文件 <%@ taglib uri="/FCKeditor" prefix="FCK" %> )

显示

<form action="show.jsp" method="post" target="_blank">

<FCK:editor id="content" basePath="/FCKeditor/" width="700" height="500" skinPath="/FCKeditor/editor/skins/silver/"

toolbarSet = "Default" >

input

</FCK:editor>

<input type="submit" value="Submit">

</form>

(2).script脚本语言调用 (必须引用 脚本文件 <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>

(3).FCKeditor API 调用 (必须加头文件 <%@ page language="java" import="com.fredck.FCKeditor.*" %> )

<form action="show.jsp" method="post" target="_blank">

<%

FCKeditor oFCKeditor ;

oFCKeditor = new FCKeditor( request, "content" ) ;

oFCKeditor.setBasePath( "/FCKeditor/" ) ;

oFCKeditor.setValue( "input" );

out.println( oFCKeditor.create() ) ;

%>

<br>

<input type="submit" value="Submit">

</form>

8.输出:

<%

String content = request.getParameter("content");

out.print(content);

%>

ok!

另:FCKeditor for Java的上传是通过servlet进行的,不是Jsp,所以配置文件web.xml中的"editor/filemanager/browser/default/connectors/jsp/connector" jsp/connector 目录并不存在,只要配置好FCKeditor.java就行了,最后上传非常快

接下来配一下Web.config和fckconfig.js,就能像我们常用的用户自定义控件一样的使用了。
    在Web.config的AppSettings中添加
    如果你用的是默认的上传功能,则
    <add key="FCKeditor:BasePath" value="~/fckeditor/"/>
    <add key="FCKeditor:UserFilesPath" value="/网站名称/UploadFiles/"/>
    如果你用的是InsertImage插件,则
    <add key ="UploadDir" value ="UploadFiles"/>
    <add key ="HostName" value ="主机名称\主机IP\http://localhost"/>  UploadFiles 是在你网站根目录下的,具有可写入的属性。其下有4个文件夹:image,flash,file,media。
    在fckconfig.js中找到FCKConfig.DefaultLanguage=en,修改为zh-cn。接着把
    var _FileBrowserLanguage = 'asp' ; // asp | aspx | cfm | lasso | perl | php | py
    var _QuickUploadLanguage = 'asp' ;// asp | aspx | cfm | lasso | perl | php | py
    修改为aspx。
    下面就可以用这个组件了。    

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>三月软件工作室--测试页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <FCKeditorV2:FCKeditor id="OnLinkEditor" runat ="server" ></FCKeditorV2:FCKeditor>
    </div>
    </form>
</body>
</html>

     这样你用的默认功能,用到的上传功能是可以浏览目录的,而且UploadFiles这个目录是可写的,这样对于服务器来说是很不安全的。如果你想自定义上传功能,并且有插入源代码的功能。那你就要接着往下看了。
    打开fckconfig.js修改FCKConfig.ToolbarSets["Default"]的值如下:  

FCKConfig.ToolbarSets["Default"] = [
    ['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],
    ['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],
    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    /*['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField']*/,
    '/',
    ['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
    ['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
    ['Link','Unlink','Anchor'],
    [/*'Image','Flash',*/'InsertCode','InsertImage','Table','Rule','Smiley','SpecialChar','PageBreak'],
    '/',
    ['Style','FontFormat','FontName','FontSize'],
    ['TextColor','BGColor'],
    ['FitWindow','ShowBlocks','-','About'],
    我们注释了原来的Image,Flash 等等,加入了InsertCode,InsertImage。这是我们想要的功能。接下来我们得注册这两个功能在文件的最后面这样加两句:
   FCKConfig.Plugins.Add( 'insertcodecommands', null, FCKConfig.BasePath + 'plugins/' ) ;
   FCKConfig.Plugins.Add( 'InsertImage', null, FCKConfig.BasePath + 'plugins/' ) ;
  并将FCKConfig.LinkBrowser = true ;FCKConfig.ImageBrowser = true ;
FCKConfig.FlashBrowser = true ;的值修改为false。


原文地址:https://www.cnblogs.com/Bany/p/1755507.html