---
title: "FCKeditor 2.6.3与FCKeditor.java 2.4在JSP中配置"
author: "lijunabc"
date: "2010-06-15T16:39:55Z"
tags: []
categories: ["Web前端"]
slug: "fckeditor-2-6-3-fckeditor-java-2-4-jsp"
draft: false
lastmod: "2010-06-15T16:39:55Z"
id: 692286
url: "https://lijunabc.iteye.com/blog/692286"
---

from:http://zfsn.iteye.com/blog/528281

1.FCKeditor 介绍

FCKeditor 这个开源的HTML 文本编辑器可以让web 程序拥有如MS Word 这样强大的编辑功能，.FCKeditor 支持当前流行的浏览器如 ，先抓个图让大家一睹她的芳容:

           

各位不要怀疑这是从OFFICE2003上抓的图哦，等您把这篇文章看完之后在您的网也中也可以拥有这样的效果了哦^\_^，废话少说，转到正题。

2．准备工作：

环境：winddows XP、tomcat6.0、JDK1.6

下载：

1）：FCKeditor\_2.6.3b.zip

地址：[http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor\_2.6.3b.zip](http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor_2.6.3b.zip)

2）：fckeditor-java-2.4-bin.zip （JAVA支持包）地址[http://nchc.dl.sourceforge.net/sourceforge/fckeditor/fckeditor-java-2.4-bin.zip](http://nchc.dl.sourceforge.net/sourceforge/fckeditor/fckeditor-java-2.4-bin.zip)

3）slf4j-1.5.2.zip 地址 ：[http://slf4j.org/dist/slf4j-1.5.2.zip](http://slf4j.org/dist/slf4j-1.5.2.zip)

3.安装：

1）解压FCKeditor\_2.6.3b.zip，将解压的到的fckeditor整个文件夹完整复制到工程目录WebRoot下。

2）解压fckeditor-java-2.4-bin.zip，在fckeditor-java-2.4-bin的解压缩文件中提取出4个JAR包，分别为fckeditor-java-core-2.4.jar、commons-fileupload-1.2.1.jar、commons-io-1.3.2.jar、slf4j-api-1.5.2.jar，

3）解压slf4j-1.5.2.zip，只需提取slf4j-jdk14-1.5.2.jar包

4）将2、3步提取的5个包都都导如工程目录WEB-INF/bin中

（

插句题外话，刚开始我只导入了第2步截压出的4个包，启动TOMCAT的时候提示找不到类org.slf4j.impl.StaticLoggerBider，再看官方文档，上面说还要下SLF4J，于是便到slf4j官网下了个最新版，但不知道org.slf4j.impl.StaticLoggerBider类在哪个包里，这是我最笨之处，我将所有包都导进去慢慢找（汗……），然后把多余包给移除了（通过项目右键→Properties→Java Build Path→Libraries，移除多余包），再重启，现在不报找不到类的错了，但出现了上百条java.lang.StackOverflowError错误（再汗……），查了N久，没结果，然后在MyEclipse的lib目录下还发现了一大堆刚才移除的包，接着我就把他们统统右键Delete删除，再重启，嘿嘿，OK了。

）

4.配置

1)在共程目录src/下新建一个文件fckeditor.properties，添加内容：connector.userActionImpl=net.fckeditor.requestcycle.impl.UserActionImpl 保存即可。

2)修改web.xml，用来提供上传功能支持，

添加内容：

Xml代码 [![复制代码](http://zfsn.iteye.com/images/icon_copy.gif)](http://zfsn.iteye.com/blog/528281 "复制代码")

1. **&lt;servlet&gt;**
2. **&lt;servlet-name&gt;**Connector**&lt;/servlet-name&gt;**

<!--THE END-->

 

01. **&lt;servlet-class&gt;**
02. net.fckeditor.connector.ConnectorServlet
03. **&lt;/servlet-class&gt;**
04. **&lt;load-on-startup&gt;**1**&lt;/load-on-startup&gt;**
05. **&lt;/servlet&gt;**
06. **&lt;servlet-mapping&gt;**
07. **&lt;servlet-name&gt;**Connector**&lt;/servlet-name&gt;**
08. **&lt;url-pattern&gt;**
09. /fckeditor/editor/filemanager/connectors/*
10. **&lt;/url-pattern&gt;**
11. **&lt;/servlet-mapping&gt;**

```
<servlet>

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

        <servlet-class>

          net.fckeditor.connector.ConnectorServlet

      </servlet-class>

      <load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

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

      <url-pattern>

        /fckeditor/editor/filemanager/connectors/*

      </url-pattern>

    </servlet-mapping>

```

 

5.应用

在工程目录WebRoot下新建index.jsp,result.jsp两个文件，

index.jsp:

Html代码 [![复制代码](http://zfsn.iteye.com/images/icon_copy.gif)](http://zfsn.iteye.com/blog/528281 "复制代码")

01. **&lt;**%@ page language="java" import="java.util.\*" pageEncoding="UTF-8"%**&gt;**
02. **&lt;**%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %**&gt;**
03. **&lt;**%
04. String path = request.getContextPath();
05. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
06. %**&gt;**
07. &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"**&gt;**
08. **&lt;html&gt;**
09. **&lt;head&gt;**
10. **&lt;base** href="&lt;%=basePath%&gt;"**&gt;**
11. **&lt;title&gt;**FCKeditor.java2.4 for FCKeditor2.6.3Beate text**&lt;/title&gt;**
12. **&lt;meta** http-equiv="Content-Type" content="text/html; charset=utf-8" **/&gt;**
13. **&lt;meta** http-equiv="pragma" content="no-cache"**&gt;**
14. **&lt;meta** http-equiv="cache-control" content="no-cache"**&gt;**
15. **&lt;meta** http-equiv="expires" content="0"**&gt;**
16. **&lt;meta** http-equiv="keywords" content="keyword1,keyword2,keyword3"**&gt;**
17. **&lt;meta** http-equiv="description" content="This is my page"**&gt;**
18. **&lt;/head&gt;**
19. **&lt;body&gt;**
20. **&lt;form** action="result.jsp" method="post"**&gt;**
21. **&lt;FCK:editor** instanceName="content"**&gt;**
22. **&lt;jsp:attribute** name="value"**&gt;**
23. 您的内容.....
24. **&lt;/jsp:attribute&gt;**
25. **&lt;/FCK:editor&gt;**
26. **&lt;input** type="submit" value="提交"**&gt;**
27. **&lt;/form&gt;**
28. **&lt;/body&gt;**
29. **&lt;/html&gt;**

```
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

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

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

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

<html>

<head>

    <base href="<%=basePath%>">

    <title>FCKeditor.java2.4 for FCKeditor2.6.3Beate text</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">   

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

</head>

<body>

    <form action="result.jsp" method="post">

    <FCK:editor instanceName="content">

    <jsp:attribute name="value">

    您的内容.....

    </jsp:attribute>

</FCK:editor>

<input type="submit" value="提交">

    </form>

   

</body>

</html>

```

 

Html代码 [![复制代码](http://zfsn.iteye.com/images/icon_copy.gif)](http://zfsn.iteye.com/blog/528281 "复制代码")

01. result.jsp
02. **&lt;**%@ page language="java" import="java.util.\*" pageEncoding="UTF-8"%**&gt;**
03. **&lt;**%
04. String path = request.getContextPath();
05. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
06. %**&gt;**
07. &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"**&gt;**
08. **&lt;html&gt;**
09. **&lt;head&gt;**
10. **&lt;base** href="&lt;%=basePath%&gt;"**&gt;**
11. **&lt;title&gt;**My JSP 'result.jsp' starting page**&lt;/title&gt;**
12. **&lt;meta** http-equiv="Content-Type" content="text/html; charset=utf-8" **/&gt;**
13. **&lt;meta** http-equiv="pragma" content="no-cache"**&gt;**
14. **&lt;meta** http-equiv="cache-control" content="no-cache"**&gt;**
15. **&lt;meta** http-equiv="expires" content="0"**&gt;**
16. **&lt;meta** http-equiv="keywords" content="keyword1,keyword2,keyword3"**&gt;**
17. **&lt;meta** http-equiv="description" content="This is my page"**&gt;**
18. **&lt;/head&gt;**
19. **&lt;body&gt;**
20. **&lt;**%=request.getParameter("content") %**&gt;**
21. **&lt;/body&gt;**
22. **&lt;/html&gt;**

```
result.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

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

<html>

<head>

    <base href="<%=basePath%>">

    <title>My JSP 'result.jsp' starting page</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">   

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

</head>

<body>

    <%=request.getParameter("content") %>

</body>

</html>

```

 

在IE地址中输入：[http://localhost:8080/FCKtest](http://localhost:8080/FCKtest)    OK,成功了！

6．不足之处

世界上没有绝对完美的女子（不知道你是否发现了完美的女孩，错了不要打我），FCK也一样。

1） 在文本框中输入中文提交后得到的中文乱码。

解决办法：

Result.JSP中来转码：

new String(request.getParameter(“content”).getByte(iso-8859-1),”UTF-8”)

试验下，嘿嘿，”汉化”成功！

2） 上传中文名图片后保存的中文图片名乱码

解决办法：下载[www.pjwqh.cn.jar](http://www.pjwqh.cn.jar/)包，替换以前下载的fckeditor-java-core-2.4.jar包，

OK，上传中文图片名显示正常了，

3） 点击浏览服务器后，选择刚上传的中文图片，图片在预览窗口中不能显示

解决办法：

修改TOMCAT安装目录config下的server.xml文件，在&lt;Connector/&gt;标签内加上 URIEncoding="UTF-8"。

OK，中文图片正常显示。

4） 关与FLASH的上传

A.上传中文文件名FLASH时，有时候弹出没有权限，或者是文件类型错误，有时候上传正常。

B.上传英文或者数字名FLASH时，窗口一直处与等待状态，过一会儿关闭窗口，再通过浏览服务器按钮可以看到FLASH已经成功上传。

C.有时候如过上传成功了，预览窗口也不能播放。

D．有时候无论使用什么语言的文件名都可以上传成功。

但只要你是使用的英文或则数字文件名，就能100%上传。

所以关于这个问题估计还是编码引起的。

5）。FCKeditor2.6.2上传文件功能与Struts 2 不兼容的问题。

解决办法：

让Struts2仅处理\*.action的请求。修改配置文件web.xml:

将Struts2处理所有web请求的过滤器配置

&lt;filter-mapping&gt;

              &lt;filter-name&gt;struts2&lt;/filter-name&gt;

              &lt;url-pattern&gt;/\*&lt;/url-pattern&gt;

       &lt;/filter-mapping&gt;

改为：仅处理.action或.jsp请求

&lt;filter-mapping&gt;

              &lt;filter-name&gt;struts2&lt;/filter-name&gt;

              &lt;url-pattern&gt;\*.action&lt;/url-pattern&gt;

       &lt;/filter-mapping&gt;

       &lt;filter-mapping&gt;

              &lt;filter-name&gt;struts2&lt;/filter-name&gt;

              &lt;url-pattern&gt;\*.jsp&lt;/url-pattern&gt;

       &lt;/filter-mapping&gt;

备注：以上配置文件的更改会造成Struts2 标签在页面中不显示

       应该在web.xml文件中加入以下配置：

&lt;filter-mapping&gt;

              &lt;filter-name&gt;struts2&lt;/filter-name&gt;

              &lt;url-pattern&gt;/struts/\*&lt;/url-pattern&gt;

       &lt;/filter-mapping&gt;

附：FCKeditor的编码是个老大难，想真正让他很好的处理中文是件非常不容易的事情，例如上面费了好大劲将中文名图片的上传和浏览功能修改好之后，FLASH又出问题。这些都是编码惹的祸。

这里附上另外一种解决办法，可以屏蔽掉上面不足之处的1、2、3、4部的操作，下载FCKeditor2.4ByTxdnet.Cn.jar这个包，用来替换上面的[www.pjwqh.cn.jar](http://www.pjwqh.cn.jar/)包，剩下的工作就是等着你测试了，这个方法方便、简单、有校，他解决中文乱码的原理是将上传的文件无论是中文文件名或者英文文件名改用系统当前时间来替换，既改成了数字，这样就永远不存在乱码和图片无法显示的问题了。（本方法又Happy漫步者提供）

7．总结：

FCKeditor2.6.3 Beta在2.6.2基础上有了很大改进，FCKeidtor 2.6.3Beta在配置上进行了大量简化，让使用者更易轻松上手，但FCKeditor的编码是个老大难问题，特别在文件上传功能上表现的尤为突出，希望FCK官方在以后的版本中能够修正这个BUG。