主文件包和你的JSP支持
http://ckeditor.com/这个是官网。
1、FCKeditor 2.6.5 下载地址:
http://sourceforge.net/projects/fckeditor/files/FCKeditor/2.6.5/FCKeditor_2.6.5.zip/download
2、FCKeditor.Java 2.3 下载地址:
http://sourceforge.net/projects/fckeditor/files/FCKeditor.Java/2.3/FCKeditor-2.3.zip/download
1、在MyEclipse下建立新项目:testFCKeditor。在WebRoot下建立文件FCKeditor。
2、解压FCKeditor_2.6.5.zip将文件夹内的editor文件夹、fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml文件拷贝到FCKeditor目录下。
3、解压FCKeditor-2.3.zip将文件夹下的src里的FCKeditor.tld文件复制到WEB-INF下。
4、将文件夹下\web\WEB-INF\lib下的两个jar文件放到你的\WEB-INF\lib目录下。
5、将下面代码添加到你的web.xml文件的<web-app>节点下。
<servlet>
<servlet-name>Connector</servlet-name>
<servlet-class>com.fredck.FCKeditor.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserFiles/</param-value><!-- 此为文件浏览路径 -->
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>SimpleUploader</servlet-name>
<servlet-class>com.fredck.FCKeditor.uploader.SimpleUploaderServlet</servlet-class>
<init-param>
<param-name>baseDir</param-name>
<param-value>/UserFiles/</param-value><!-- 此为文件上传路径,需要在WebRoot 目录下新建 UserFiles 文件夹,在UserFiles文件夹下建立Image、Flash和File文件夹用来保存用户上传的各类文件 -->
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>enabled</param-name>
<param-value>true</param-value><!-- 设置为true开启上传功能-->
</init-param>
<init-param>
<param-name>AllowedExtensionsFile</param-name><!-- 可以上传的文件类型 -->
<param-value></param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFile</param-name><!-- 不可以上传的文件类型 -->
<param-value>php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi</param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsImage</param-name><!-- 可以上传的图片类型 -->
<param-value>jpg|gif|jpeg|png|bmp</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsImage</param-name><!-- 不可以上传的图片类型 -->
<param-value></param-value>
</init-param>
<init-param>
<param-name>AllowedExtensionsFlash</param-name><!-- 可以上传的flash类型 -->
<param-value>swf|fla</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFlash</param-name><!-- 不可以上传的flash类型 -->
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name><!-- 此处注意路径问题,因为我们刚才在WebRoot下建立了FCKeditor文件夹所在要加上红字部分 -->
<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>
6、修改FCKeditor文件夹下的fckeditor.js文件。
修改第50行:FCKeditor.BasePath = 'FCKeditor/' ;
7、修改FCKeditor文件夹下的fckconfig.js文件。
FCKConfig.DefaultLanguage = 'zh-cn' ;
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' ;
8、打开你的index.jsp文件改成以下内容:
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FCKeditor测试</title>
<script type="text/javascript" src="FCKeditor/fckeditor.js"></script>
</head>
<body>
<form id="form1" name="form1" method="post" action="index_do.jsp">
<table width="100%" border="0">
<tr>
<td height="25">
<textarea name="contest" id="contest" style="width:100%; height:400px;"></textarea>
<script type="text/javascript">
var oFCKeditor = new FCKeditor( 'contest' ) ;
oFCKeditor.BasePath = 'FCKeditor/' ;
oFCKeditor.ToolbarSet = 'Default' ;
oFCKeditor.Width = '100%' ;
oFCKeditor.Height = '400' ;
oFCKeditor.Value = '' ;
oFCKeditor.ReplaceTextarea();
//oFCKeditor.Create() ;
</script>
<input type="submit" name="Submit" value="提交" />
</td>
</tr>
</table>
</form>
</body>
</html>
9、新建index_do.jsp文件改成以下内容:
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>FCKeditor测试接收结果</title>
</head>
<body>
<%
String contest = new String(request.getParameter("contest").getBytes("ISO8859_1"), "utf-8");
out.print(contest);
%>
</body>
</html>
index.jsp效果
fck_docprops.html报错解决
在Java的工程中加入fck时MyEclipse会包fck_docprops.html错误,原因是因为用了怪异的标签,没有告诉MyEclipse,解决方法:
选中当前工程—properties—MyEclipse—validation—Excluded Resource下找到fck_docprops.html打钩就可以不检查该文件了,然后就不报错了!