日期:2014-05-17  浏览次数:20735 次

HTML编辑器FCKeditor使用详解
一、简介

功能:所见即所得,支持图片和Flash,工具栏可自由配置,使用简单
兼容性:IE 5.5+、Firefox 1.5+、Safari 3.0+、Opera 9.50+、Netscape 7.1+、 Camino 1.0+
成熟度:使用广泛,被Baidu、CSDN等选用

二、首先下载相关文件

FCKeditor_2.3.2.zip

http://prdownloads.sourceforge.net/fckeditor/FCKeditor_2.3.2.zip?download

FCKeditor-2.3 (for java)

http://nchc.dl.sourceforge.net/sourceforge/fckeditor/FCKeditor-2.3.zip

三、安装与例子

1> 下载完成后,在J2EE应用中,建立项目:agrilink,在应用根目录中建立文件夹FCKeditor,将FCKeditor中的editor目录及 fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml文件拷贝到FCKeditor目录下。

2> 然后我们将FCKeditor-2.3\web\WEB-INF\lib中的两个jar包拷贝到\agrilink\WEB-INF\lib目录下,将 FCKeditor-2.3\src下的FCKeditor.tld拷贝到\agrilink\WEB-INF下。

3> 编辑\agrilink\WEB-INF\web.xml文件,将FCKeditor-2.3\web\WEB-INF\web.xml里的内容合并到项目的\WEB-INF\目录下的web.xml文件中,修改<servlet-mapping>里的内容为:
    <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>


4>  修改合并后的web.xml文件,将名为SimpleUploader的Servlet的enabled参数值改为true,以允许上传功能,Connector Servlet的baseDir参数值用于设置上传文件存放的位置。
    并在</servlet-mapping>后面添加下面内容
  <taglib>
    <taglib-uri>/FCKeditor</taglib-uri>
    <taglib-location>/WEB-INF/FCKeditor.tld</taglib-location>
    </taglib>


5>修改页面fckconfig.js

将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.ImageUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Image';

FCKConfig.FlashUploadURL = FCKConfig.BasePath +'filemanager/upload/simpleuploader?Type=Flash';


6> 添加页面testUpload.jsp
<%@    page contentType="text/html;charset=GBK"%>
<html>
<head>
<title>FCKeditor Test</title>
<script type="text/javascript" src="FCKeditor/fckeditor.js"></script>
</head>
<body>
<form action="testUpload.jsp" method="post">

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

<table width=100%>
<tr><td><input type="text" value="" name=title id=title/></td></tr>
<tr>
    <td colspan=4 style='text-align:center' width=100% height=50px>
    <span>
        <script type="text/javascript">
            var oFCKeditor = new FCKeditor('content');//传入参数为表单元素(由FCKeditor生成的input或textarea)的name
            oFCKeditor.BasePath='FCKeditor/';//指定FCKeditor根路径,也就