升级系统时使用FCKEditor时上传文件不符合需求,自己下了一份源码修改了ConnectorServlet,实现自己的上传
FCKEditor的版本2.6.6,源码下载连接http://sourceforge.net/projects/fckeditor/files/FCKeditor.Java/2.6/
把源码拷贝到自己的项目中修改ConnectorServlet的init()方法
/**ConnectorSerlvet的初始方法*/
public void init() throws ServletException {
String className = PropertiesLoader.getConnectorImpl();
if (Utils.isEmpty(className))
logger.error("Empty Connector implementation class name provided");
else {
try {
Class<?> clazz = Class.forName(className);
connector = (Connector) clazz.newInstance();
logger.info("Connector initialized to {}", className);
connector.init(getServletContext());
logger.error("Connector implementation {} could not be
} catch (Throwable e) {instantiated", className);
throw new RuntimeException("Connector implementation " + className + " could not be instantiated", e); //$NON-NLS-1$
}
}
/**获取fileService的服务*/
fileService = (FileService) StaticSpringContextHelper.getBeanByName("fileService");
}
然后根据自己的上传需求修改doPost()方法【我们采用的FTP的形式上传到服务器】,
源码中List<FileItem> items = upload.parseRequest(request); FileItem uplFile = items.get(0);是获取上传的文件,在这里可以根据自己的需求修改上传
可以通过uploadresponse = new UploadResponse(状态码,上传文件路径,文件名,自定义信息);来返回自定义的上传文件信息
在fckeditor/editor/dialog/fck_image/fck_image.js文件中找到OnUploadCompleted()方法,新增case 状态码:alert(自定义信息)来提示自定义的信息。
修改web.xml
<servlet>
<servlet-name>ConnectorServlet</servlet-name>
<!--com.aweb.cms.fckeditor.ConnectorServlet-->
<!--net.fckeditor.connector.ConnectorServlet-->
<servlet-class>
com.aweb.cms.fckeditor.ConnectorServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ConnectorServlet</servlet-name>
<url-pattern>/static/js/fckeditor/editor/filemanager/*</url-pattern>
</servlet-mapping>
在添加Jar文件时commons-fileupload-1.2.1.jar,commons-io-1.3.2.jar,fckeditor-java-core-2.6.jar,imageinfo-1.9.jar,slf4j-api-1.5.8.jar不太支持,把它换成slf4j-api-1.6.1.jar就可以了