posts - 2, comments - 27, trackbacks - 0, articles - 60
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

在JSP中配置FCKeditor 2.6.4

Posted on 2009-06-02 17:42 ZhouFeng 阅读(6133) 评论(7)  编辑  收藏 所属分类: 转载CKEditor
1.FCKeditor 介绍
FCKeditor 这个开源的HTML 文本编辑器可以让web 程序拥有如MS Word 这样强大的编辑功能,.FCKeditor 支持当前流行的浏览器。

2.准备工作:

环境:winddows XP、tomcat6.0、JDK1.6
下载:
1):FCKeditor_2.6.4.zip
地址:http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor_2.6.4.zip

2):fckeditor-java-2.4.1-bin.zip (JAVA支持包)地址http://nchc.dl.sourceforge.net/sourceforge/fckeditor/fckeditor-java-2.4.1-bin.zip

3):slf4j-1.5.2.zip 地址 :http://www.slf4j.org/dist/slf4j-1.5.2.zip

3.安装:

下面以jsp为例:

分别解压之后,我们可以得到一个fckeditor和fckeditor-java-2.4.1两个文件夹。fckeditor文件夹下是需要调用的页面和js文件等等,有各种版本,无所谓啦,我们之需要jsp就够了。将文件加全部复制到工程目录下等待调用即可。
注意:有点麻烦的是导包的问题。我们一共需要5个包:commons-fileupload-1.2.1.jar,commons-io-1.3.2.jar,fckeditor-java-core-2.4.1.jar,slf4j-api-1.5.6.jar,slf4j-simple-1.5.6.jar或slf4j-jdk14-1.5.6.jar。
上面前四个包都可以在fckeditor-java-2.4.1文件夹下面找到,但是第五个却要另外去找,这点我非常不理解,为什么不放在一起。
如果没有的话编译时就会出现如下错误信息:
严重: Servlet /fckeditorDemo threw load() exception
java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder



当然版本或许不同,以上的版本是截止2009-02-4的最新版本。如果想要最新版本,可以在slf4j的官网http://www.slf4j.org/download.html下到。但是要注意,截止到2009-2-4,slf4j官方最新版本是1.5.6,但是fckeditor提供的slf4j-api却是1.5.2版本,如果两个版本不一样的话,你将会在控制台看到如下的消息:

严重: Servlet /Java threw load() exception
java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class

org.slf4j.LoggerFactory



所以千万要注意版本一致问题。如果你实在觉得下载很麻烦,那就到这里下载吧:http://www.slf4j.org/download.html


4.配置

1)在工程目录src/下新建一个文件fckeditor.properties,添加内容:
connector.userFilesPath=UploadFile
connector.userActionImpl
=net.fckeditor.requestcycle.impl.UserActionImpl
其中第一行为重新定义上传的文件夹,默认文件夹为userfile,保存即可。
2)修改web.xml,用来提供上传功能支持
<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.应用,建立一JSP文件如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String content=request.getParameter("edt1");
if (content != null) {
  content 
= content.replaceAll("\r\n""");
  content 
= content.replaceAll("\r""");
  content 
= content.replaceAll("\n""");
  content 
= content.replaceAll("\"", "'");
}else{
  content 
= "";
}

//下面是处理中文内容的编码转换
content 
= new String(content.getBytes("iso8859-1"),"utf-8");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  
<head>
    
<base href="<%=basePath%>">
    
    
<title>FCKEditor 测试</title>

  
</head>
  
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
  
<body>
    This is my JSP page. 
<br>
    
<form method="post" name="frm1">
    
<script type="text/javascript">
        
var oFCKeditor = new FCKeditor("edt1");
        oFCKeditor.BasePath 
= "fckeditor/";
        oFCKeditor.Height
='400';
        oFCKeditor.Value
="<%=content%>";
        oFCKeditor.Create();
    
</script>
    
<input type="submit" value="提交">
    
</form>
    
<hr>
    
<%=content%>
  
</body>
</html>
启动服务器,用浏览器访问即可看到结果

今天折腾了一个下午,终于算是看到点效果了,便记录在这里,上面的内容在网上转了一部分,因为找不到原文出处,也就没有注明了

评论

# re: 在JSP中配置FCKeditor 2.6.4  回复  更多评论   

2009-08-21 03:37 by lzg
slf4j-simple-1.5.6.jar---------
先用1.5.2的如你所说报错了。
又去下,只看见有1.5.8的版本。
刚好,换上去可以用。
半夜研究了好半天,
本来说这次失败也睡觉去的。
—_—#

竟然成功了,但是跟我之前网上看到的方法有好大的差异,
这点有点困惑。
谢谢你的分享。

# re: 在JSP中配置FCKeditor 2.6.4  回复  更多评论   

2009-08-23 21:38 by 李凯
呵呵,谢谢

# re: 在JSP中配置FCKeditor 2.6.4  回复  更多评论   

2009-12-01 10:37 by dubi
超正确的文章,谢谢

# re: 在JSP中配置FCKeditor 2.6.4  回复  更多评论   

2009-12-09 19:51 by 笑话论坛
我用是的2.6.5的。
测试是没出问题,只是中文用不了
会出现乱码

# re: 在JSP中配置FCKeditor 2.6.4  回复  更多评论   

2009-12-09 20:37 by 笑话论坛
自己再配置一篇,竟然图片上传不了

# re: 在JSP中配置FCKeditor 2.6.4[未登录]  回复  更多评论   

2010-03-10 15:09 by aaa
connector.userFilesPath=UploadFile
这个地方应该改为:connector.userFilesPath=/UploadFile

# re: 在JSP中配置FCKeditor 2.6.4[未登录]  回复  更多评论   

2015-04-06 15:14 by ff
嘻嘻嘻嘻嘻嘻想

只有注册用户登录后才能发表评论。


网站导航: