FCKeditor编辑器在JAVA中的使用与配置
2007-10-30 09:43
531 查看
工作前的准备
版本是FCKeditor_2.4.2.zip【组件的主文件包】,FCKeditor.Java 2.3.zip【这里面提供了标签库和图片上传的jar】。这些都可以在http://www.fckeditor.net 网站下载到!
配置
1. 新建工程FCKeditor,在WebRoot文件夹下新建文件夹FCKeditor(用来存放FCKeditor相关文件,
记得大小写要一致,因为如果你需要改变的话变化的文件比较多,而且还不确定是否改全了)
2. 将FCKeditor_2.4.2包中的 editor 文件夹和fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml
这四个文件放到项目中的 FCKeditor 目录。
3. 将FCKeditor.Java -2.3.zip 包中的 /web/WEB-INF/lib 下的两个 jar 文件到项目的 WebRoot/WEB-INF/lib目录下
4. 将FCKeditor.Java -2.3.zip 包中的 /src 下的 FCKeditor.tld 文件到项目的 WebRoot/WEB-INF 目录
5. 在 WebRoot 目录下新建 UserFiles 文件夹,在此文件夹下新建 Image、 Flash 、File、Media四个文件夹 ,他们分别用来存放上传的图片、动画、文件、媒体文件
6. 修改fckconfig.js组件配置文件【说明一下,你可以在配置文件里搜索等号前面的信息来确定某一项做更改】:
A、FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/' ;
这是组件的样式模板,好确定你到底需要使用哪中样式,这个根据你自己的喜好更改,
B、FCKConfig.DefaultLanguage = 'zh-cn' ;
这个是确定你需要使用哪中语言,设定成上面的表示使用简体中文;
C、更改文件浏览的路径:
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" ;
把相应的信息屏蔽掉,使用上面的
D、更改上传文件的路径
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' ;
把相应的信息屏蔽掉,使用上面的
7. 修改 web.xml 文件,加入以下内容 :
在FCKeditor.Java -2.3.zip 包中有个web/WEB-INF/WEB.XML,把这个节点里面的内容复制到你的工程里面的相应的位置,值得说明的地方是:
<servlet-name>Connector</servlet-name>
<servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<!-- 此为文件浏览路径,可以只有选择修改,但切记不可改成“/[工程名]/UserFiles/”
因为他目前已经是在工程的根目录下来运行的,故如果要把默认浏览的文件目录为
webroot/upload目录,之需要改变成:/upload/,即可 -->
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<servlet-name>SimpleUploader</servlet-name>
<servlet-class>com.fredck.FCKeditor.uploader.SimpleUploaderServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<!-- 此为文件上传路径,可以只有选择修改,但切记不可改成“/[工程名]/UserFiles/”
因为他目前已经是在工程的根目录下来运行的,故如果要把上传的文件放到webroot/upload目录下,
之需要改变成:/rpload/,即可 -->
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!-- 记得要改变这里,把FALSE改变成TRUE,这个是是否启用上传功能 -->
<param-name>enabled</param-name>
<param-value>true</param-value>
</init-param>
<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>
优化
以上都是把组件嵌入进工程的 配置过程,下面我们来把组件压缩优化一下,把无用的文件给剔除掉:
删除 /WebRoot/FCKeditor/editor/filemanager/browser/default/connectors 目录下所有的文件,这些是用来浏览文件的,对于jsp的话是使用了 servlet 来处理,所以这些文件都是多余的
删除 /WebRoot/FCKeditor/editor/filemanager/upload 目录下所有的文件
删除 WebRoot/FCKeditor/editor/lang 目录下不需要的语言,如保留中文【zh-cn.js】和英文[EN.js]还有 fcklanguagemanager.js 文件
删除 /WebRoot/FCKeditor/editor/skins 目录下不需要的皮肤文件,有三种皮肤,可根据需要进行删除
测试页面:
<%...@ page language="java" import="com.fredck.FCKeditor.*" %>
<!--
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: sample01.jsp
* FCKeditor sample file 1.
*
* Version: 2.1
* Modified: 2005-03-29 21:30:00
*
* File Authors:
* Simone Chiaretta (simo@users.sourceforge.net)
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>FCKeditor - JSP Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex, nofollow">
<link href="../sample.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">...
function FCKeditor_OnComplete( editorInstance )
...{
window.status = editorInstance.Description ;
}
</script>
</head>
<body>
<h1>FCKeditor - JSP - Sample 1</h1>
This sample displays a normal HTML form with an FCKeditor with full features
enabled.
<hr>
<form action="sampleposteddata.jsp" method="get" target="_blank">
<%...
FCKeditor oFCKeditor ;
oFCKeditor = new FCKeditor( request, "filename" ) ;
oFCKeditor.setBasePath( "/FCKeditor/FCKeditor/" ) ;
oFCKeditor.setHeight("80%");
oFCKeditor.setWidth("80%");
oFCKeditor.setValue( "" );
out.println( oFCKeditor.create() ) ;
%>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
其它
1、fckconfig.js总配置文件,可用记录本打开,修改后将文件存为utf-8 编码格式。找到:
FCKConfig.TabSpaces = 0 ; 改为FCKConfig.TabSpaces = 1 ; 即在编辑器域内可以使用Tab键。
2、如果你的编辑器还用在网站前台的话,比如说用于留言本或是日记回复时,那就不得不考虑安全
了,在前台千万不要使用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,图像按钮”功能都去掉。
3、找到: 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' ;
4、注意上传的文件名不能有中文,否则无法正常显示或链接下载。
注意:例子里面只有例一和例二修改了,其它例子中的basePath="/FCKeditor/FCKeditor/"应该做相应的修改。
配置好的工程在资源里面下载。
版本是FCKeditor_2.4.2.zip【组件的主文件包】,FCKeditor.Java 2.3.zip【这里面提供了标签库和图片上传的jar】。这些都可以在http://www.fckeditor.net 网站下载到!
配置
1. 新建工程FCKeditor,在WebRoot文件夹下新建文件夹FCKeditor(用来存放FCKeditor相关文件,
记得大小写要一致,因为如果你需要改变的话变化的文件比较多,而且还不确定是否改全了)
2. 将FCKeditor_2.4.2包中的 editor 文件夹和fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml
这四个文件放到项目中的 FCKeditor 目录。
3. 将FCKeditor.Java -2.3.zip 包中的 /web/WEB-INF/lib 下的两个 jar 文件到项目的 WebRoot/WEB-INF/lib目录下
4. 将FCKeditor.Java -2.3.zip 包中的 /src 下的 FCKeditor.tld 文件到项目的 WebRoot/WEB-INF 目录
5. 在 WebRoot 目录下新建 UserFiles 文件夹,在此文件夹下新建 Image、 Flash 、File、Media四个文件夹 ,他们分别用来存放上传的图片、动画、文件、媒体文件
6. 修改fckconfig.js组件配置文件【说明一下,你可以在配置文件里搜索等号前面的信息来确定某一项做更改】:
A、FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/' ;
这是组件的样式模板,好确定你到底需要使用哪中样式,这个根据你自己的喜好更改,
B、FCKConfig.DefaultLanguage = 'zh-cn' ;
这个是确定你需要使用哪中语言,设定成上面的表示使用简体中文;
C、更改文件浏览的路径:
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" ;
把相应的信息屏蔽掉,使用上面的
D、更改上传文件的路径
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' ;
把相应的信息屏蔽掉,使用上面的
7. 修改 web.xml 文件,加入以下内容 :
在FCKeditor.Java -2.3.zip 包中有个web/WEB-INF/WEB.XML,把这个节点里面的内容复制到你的工程里面的相应的位置,值得说明的地方是:
<servlet-name>Connector</servlet-name>
<servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<!-- 此为文件浏览路径,可以只有选择修改,但切记不可改成“/[工程名]/UserFiles/”
因为他目前已经是在工程的根目录下来运行的,故如果要把默认浏览的文件目录为
webroot/upload目录,之需要改变成:/upload/,即可 -->
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<servlet-name>SimpleUploader</servlet-name>
<servlet-class>com.fredck.FCKeditor.uploader.SimpleUploaderServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<!-- 此为文件上传路径,可以只有选择修改,但切记不可改成“/[工程名]/UserFiles/”
因为他目前已经是在工程的根目录下来运行的,故如果要把上传的文件放到webroot/upload目录下,
之需要改变成:/rpload/,即可 -->
<param-value>/UserFiles/</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<!-- 记得要改变这里,把FALSE改变成TRUE,这个是是否启用上传功能 -->
<param-name>enabled</param-name>
<param-value>true</param-value>
</init-param>
<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>
优化
以上都是把组件嵌入进工程的 配置过程,下面我们来把组件压缩优化一下,把无用的文件给剔除掉:
删除 /WebRoot/FCKeditor/editor/filemanager/browser/default/connectors 目录下所有的文件,这些是用来浏览文件的,对于jsp的话是使用了 servlet 来处理,所以这些文件都是多余的
删除 /WebRoot/FCKeditor/editor/filemanager/upload 目录下所有的文件
删除 WebRoot/FCKeditor/editor/lang 目录下不需要的语言,如保留中文【zh-cn.js】和英文[EN.js]还有 fcklanguagemanager.js 文件
删除 /WebRoot/FCKeditor/editor/skins 目录下不需要的皮肤文件,有三种皮肤,可根据需要进行删除
测试页面:
<%...@ page language="java" import="com.fredck.FCKeditor.*" %>
<!--
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
*
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
*
* For further information visit:
* http://www.fckeditor.net/
*
* File Name: sample01.jsp
* FCKeditor sample file 1.
*
* Version: 2.1
* Modified: 2005-03-29 21:30:00
*
* File Authors:
* Simone Chiaretta (simo@users.sourceforge.net)
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>FCKeditor - JSP Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex, nofollow">
<link href="../sample.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">...
function FCKeditor_OnComplete( editorInstance )
...{
window.status = editorInstance.Description ;
}
</script>
</head>
<body>
<h1>FCKeditor - JSP - Sample 1</h1>
This sample displays a normal HTML form with an FCKeditor with full features
enabled.
<hr>
<form action="sampleposteddata.jsp" method="get" target="_blank">
<%...
FCKeditor oFCKeditor ;
oFCKeditor = new FCKeditor( request, "filename" ) ;
oFCKeditor.setBasePath( "/FCKeditor/FCKeditor/" ) ;
oFCKeditor.setHeight("80%");
oFCKeditor.setWidth("80%");
oFCKeditor.setValue( "" );
out.println( oFCKeditor.create() ) ;
%>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
其它
1、fckconfig.js总配置文件,可用记录本打开,修改后将文件存为utf-8 编码格式。找到:
FCKConfig.TabSpaces = 0 ; 改为FCKConfig.TabSpaces = 1 ; 即在编辑器域内可以使用Tab键。
2、如果你的编辑器还用在网站前台的话,比如说用于留言本或是日记回复时,那就不得不考虑安全
了,在前台千万不要使用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,图像按钮”功能都去掉。
3、找到: 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' ;
4、注意上传的文件名不能有中文,否则无法正常显示或链接下载。
注意:例子里面只有例一和例二修改了,其它例子中的basePath="/FCKeditor/FCKeditor/"应该做相应的修改。
配置好的工程在资源里面下载。
相关文章推荐
- FCKeditor编辑器在JAVA中的使用与配置
- FCKeditor编辑器在JAVA中的使用与配置方法
- FCKeditor编辑器在JAVA中的使用与配置
- FCKeditor编辑器在JAVA中的使用与配置
- FCKeditor编辑器在JAVA中的使用与配置
- FCKeditor编辑器在JAVA中的使用与配置
- FCKeditor编辑器在JAVA中的使用与配置方法
- FCKeditor编辑器在JAVA中的使用与配置
- Ckeditor编辑器在JAVA中的使用与配置
- 在线编辑器fckeditor的精简,使用和配置
- out.println()使用及FCKeditor编辑器的配置和使用
- FCKeditor是使用非常广泛的HTML编辑器,本文从 ASP.NET 的使用场景对 FCKeditor 与 FCKeditor.NET 的配置、功能扩展(如自定义文件上传子目录、自定义文件名、上传图片的后期处理等)、以及安全性进行初步的阐述。
- FckEditor配置,FCK编辑器使用手册
- PHP FCKeditor 在线编辑器的配置和使用实例
- jsp中使用FCKeditor编辑器组件的配置和优化
- 在java项目中使用fckeditor编辑器步骤
- Ckeditor编辑器在JAVA中的使用与配置
- 在线编辑器fckeditor的精简,使用和配置
- java web and vue.js 配合使用---servlet的配置
- 使用java内置keytool配置tomcat双向SSL认证