修改ConnectorServlet.java(负责浏览文件夹和文件上传)和SimpleUploaderServlet.java(复制直接上传文件)后可以实现将用户的Image和Flash文件传到各用户自己的文件夹内
文件夹的名字要和Session中的userId字段相关联。
即在jsp文件中要设置session.setAttribute("userId",用户主键);
存在的问题:
1、 中文命名的文件不支持。
2、 文件夹的删除不支持。
编译要求:
修改build.xml文件中的
复制D:\Tomcat 5.5\server\lib\catalina-ant.jar到D:\DevelopEnvironments\apache-ant-1.7.1\lib目录下
将FCKeditor-2.3.jar和commons-fileupload.jar拷贝到工程的Lib文件夹下
在MyEclipse5.5中创建FCKEditorTest项目
在项目中新建文件夹 fckeditor_2.6
将解压后的FCKeditor_2.6下fckeditor里面的editor目录及fckconfig.js、fckeditor.js、fckpackager.xml、fckstyles.xml、fcktemplates.xml文件拷贝到test项目的fckeditor_2.6目录下
将FCKeditor-2.3文件夹下src下的FCKeditor.tld拷贝到test项目的WEB-INF下。
修改WEB-INF下的web.xml如下:
<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>
</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>
</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>
<param-value>swf|fla</param-value>
</init-param>
<init-param>
<param-name>DeniedExtensionsFlash</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Connector</servlet-name>
<url-pattern>/fckeditor_2.6/editor/filemanager/browser/default/connectors/jsp/connector</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SimpleUploader</servlet-name>
<url-pattern>/fckeditor_2.6/editor/filemanager/upload/simpleuploader</url-pattern>
</servlet-mapping>
4、修改FCKeditor文件夹下的fckeditor.js
修改第50行的FCKeditor.BasePath。
改之后:
50:FCKeditor.BasePath = 'fckeditor_2.6/';
5、修改FCKeditor文件夹下的fckconfig.js
修改:
FCKConfig.DefaultLanguage、FCKConfig.LinkBrowserURL、FCKConfig.ImageBrowserURL、FCKConfig.FlashBrowserURL、FCKConfig.LinkUploadURL、FCKConfig.ImageUploadURL、FCKConfig.FlashUploadURL。
改之后:
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';
6、default.jsp内容如下:
<%@ page contentType="text/html; charset=gb2312" 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>
<script type="text/javascript" src="fckeditor_2.6/fckeditor.js"></script>
</head>
<body>
<%
request.getSession().setAttribute("userId","lauvenman");
%>
<form method="post" action="default_do.jsp">
<table width="100%" border="0">
<tr>
<td height="25">
<textarea style="width:100%; height:400px;" id="contest" name="contest">默认html或文字</textarea>
<script type="text/javascript">
var oFCKeditor = new FCKeditor('contest');
oFCKeditor.BasePath = 'fckeditor_2.6/';
oFCKeditor.ToolbarSet = 'Default';
oFCKeditor.Width = '100%';
oFCKeditor.Height = '400';
oFCKeditor.Value = 'Hello World';
oFCKeditor.ReplaceTextarea();
//oFCKeditor.Create();
</script>
<input type="submit" value="提交"