怎么在java web程序中添加fckeditor?
1、下载 fckeditor for java包, 解压放到WebRoot下
2、新建html,内容如下:
a) 注意导入fckeditor.js
b) sBasePath 路径,这是加上了http://192.168.0.141:8012/Demo/的地址。
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> <script type="text/javascript" src="../FCKeditor/fckeditor.js"></script> <script type="text/javascript"> var sBasePath = document.location.href.substring(0,document.location.href.lastIndexOf('yx')); function load(){ var fckobj = new FCKeditor('f_content'); //alert(sBasePath); fckobj.BasePath = sBasePath +"FCKeditor/" ; fckobj.Height = 300; fckobj.Width = 530; fckobj.ReplaceTextarea(); } </script> </head> <body id="body" onload="load()"> <textarea id="f_content"></textarea> </body> </html>
3、拷贝如下内容到web.xml中:
a) 注意baseDir是上传文件地址
b ) 拷贝fckeditor-java-core-2.4.1.jar、slf4j-api-1.5.2.jar、slf4j-simple-1.5.2.jar、commons-io- 1.3.2.jar、commons-fileupload-1.2.1.jar到classpath中
<!-- fckeditor upload servlet begin --> <servlet> <servlet-name>Connector</servlet-name> <servlet-class> net.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-mapping> <servlet-name>Connector</servlet-name> <!-- Do not wrap this line otherwise Glassfish will fail to load this file --> <url-pattern>/FCKeditor/editor/filemanager/connectors/*</url-pattern> </servlet-mapping>
4、文件目录解释:
该目录为FCKeditor的核心目录,包含了FCKeditor的核心文件,其中: (1) _source为FCKEditor的源文件目录 (2) css为FCKeditor的样式文件目录 (3) dialog为FCKeditor工具栏中相应的工具按钮的弹出对话框文件目录 (4) filemanager为FCKeditor处理文件上传的文件目录 (5) images为FCKeditor中增加表情头像等资源的图像文件目录 (6) js为FCKeditor的核心javascript文件目录 (7) lang为FCKeditor的语言文件目录,包含国际化支持。 (8) plugins为FCKeditor的插件目录,FCKeditor的插件开发文件都放入该目录 (9) skins为FCKeditor的皮肤文件,自带三种皮肤文件default,office2003和silver。
5、拷贝fckeditor.properties到classpath下,实例内容为:
connector.userActionImpl=com.huitu.khms.util.UserActionImpl connector.resourceType.flash.extensions.allowed=swf|fla|mpg|asf|wma|wmv|avi|mov|mp3|rmvb|mid
UserActionImpl
package com.huitu.khms.util; import javax.servlet.http.HttpServletRequest; import net.fckeditor.requestcycle.UserAction; public class UserActionImpl implements UserAction { public boolean isEnabledForFileBrowsing(HttpServletRequest req) { return true; } public boolean isEnabledForFileUpload(HttpServletRequest req) { return true; } }
ok了