- 浏览: 10048 次
- 性别:
- 来自: 武汉
最近访客 更多访客>>
最新评论
-
GoTiger:
谢谢 由于我们新的项目是9月30号要上线,所以进度有点赶,每天 ...
Spring3.0 mvc 初接触 -
yzhw:
期待下一篇
Spring3.0 mvc 初接触 -
jzinfo:
嗯 新帖
当初也是这样一步一步走来的
Spring3.0 mvc 初接触
首先要将下载的fckeditor_2.6.4.zip解压出来的文件复制出来,放到项目中的WebRoot下,并且导入6个jar包(commons-fileupload-1.2.1.jar,commons-io-1.3.2.jar,fckeditor-java-core-2.4.1.jar,slf4j-api-1.5.2.jar,slf4j-jdk14-1.5.2.jar,slf4j-simple-1.5.2jar)相关资源就去网上下载吧。
新建一个ConnectorServlet类
改动如下
Web.xml加入以下代码
Jsp页面中头部加入
使用FCK的标签调用
最后需要在TOMCAT的server.xml中加入URIEncoding="UTF-8",就完成了
附件中是教我的一个朋友 写的DEMO,共享咯
新建一个ConnectorServlet类
改动如下
package com.bluebird.fckeditor; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.fckeditor.connector.Messages; import net.fckeditor.handlers.*; import net.fckeditor.tool.UtilsFile; import net.fckeditor.tool.UtilsResponse; import net.fckeditor.tool.Utils; import net.fckeditor.response.XmlResponse; import net.fckeditor.response.UploadResponse; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.ArrayList; /** * Created by IntelliJ IDEA. * Date: 2009-6-19 * Time: 11:14:24 * To change this template use File | Settings | File Templates. */ public class ConnectorServlet extends javax.servlet.http.HttpServlet { private static final long serialVersionUID = -5742008970929377161L; private static final Logger logger = LoggerFactory.getLogger(ConnectorServlet.class); /** * Initialize the servlet: <code>mkdir</code> <DefaultUserFilesPath> */ public void init() throws ServletException, IllegalArgumentException { String realDefaultUserFilesPath = getServletContext().getRealPath( ConnectorHandler.getDefaultUserFilesPath()); File defaultUserFilesDir = new File(realDefaultUserFilesPath); UtilsFile.checkDirAndCreate(defaultUserFilesDir); logger.info("ConnectorServlet successfully initialized!"); } /** * Manage the <code>GET</code> requests (<code>GetFolders</code>, * <code>GetFoldersAndFiles</code>, <code>CreateFolder</code>).<br/> * * The servlet accepts commands sent in the following format:<br/> * <code>connector?Command=<CommandName>&Type=<ResourceType>&CurrentFolder=<FolderPath></code> * <p> * It executes the commands and then returns the result to the client in XML * format. * </p> */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("Entering ConnectorServlet#doGet"); response.setCharacterEncoding("UTF-8"); response.setContentType("application/xml; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); String commandStr = request.getParameter("Command"); String typeStr = request.getParameter("Type"); String currentFolderStr = request.getParameter("CurrentFolder"); logger.debug("Parameter Command: {}", commandStr); logger.debug("Parameter Type: {}", typeStr); logger.debug("Parameter CurrentFolder: {}", currentFolderStr); XmlResponse xr; if (!RequestCycleHandler.isEnabledForFileBrowsing(request)) xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.NOT_AUTHORIZED_FOR_BROWSING); else if (!CommandHandler.isValidForGet(commandStr)) xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.INVALID_COMMAND); else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr)) xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.INVALID_TYPE); else if (!UtilsFile.isValidPath(currentFolderStr)) xr = new XmlResponse(XmlResponse.EN_ERROR, Messages.INVALID_CURRENT_FOLDER); else { CommandHandler command = CommandHandler.getCommand(commandStr); ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr); String typePath = UtilsFile.constructServerSidePath(request, resourceType); String typeDirPath = getServletContext().getRealPath(typePath); File typeDir = new File(typeDirPath); UtilsFile.checkDirAndCreate(typeDir); File currentDir = new File(typeDir, currentFolderStr); if (!currentDir.exists()) xr = new XmlResponse(XmlResponse.EN_INVALID_FOLDER_NAME); else { xr = new XmlResponse(command, resourceType, currentFolderStr, UtilsResponse .constructResponseUrl(request, resourceType, currentFolderStr, true, ConnectorHandler.isFullUrl())); if (command.equals(CommandHandler.GET_FOLDERS)) xr.setFolders(currentDir); else if (command.equals(CommandHandler.GET_FOLDERS_AND_FILES)) xr.setFoldersAndFiles(currentDir); else if (command.equals(CommandHandler.CREATE_FOLDER)) { //修改新建文件夹中文乱码 String temStr= request.getParameter("NewFolderName"); //temStr=new String(temStr.getBytes("iso8859-1"),"utf-8"); // 完毕 String newFolderStr = UtilsFile.sanitizeFolderName(temStr); logger.debug("Parameter NewFolderName: {}", newFolderStr); File newFolder = new File(currentDir, newFolderStr); int errorNumber = XmlResponse.EN_UKNOWN; if (newFolder.exists()) errorNumber = XmlResponse.EN_ALREADY_EXISTS; else { try { errorNumber = (newFolder.mkdir()) ? XmlResponse.EN_OK : XmlResponse.EN_INVALID_FOLDER_NAME; } catch (SecurityException e) { errorNumber = XmlResponse.EN_SECURITY_ERROR; } } xr.setError(errorNumber); } } } out.print(xr); out.flush(); out.close(); logger.debug("Exiting ConnectorServlet#doGet"); } /** * Manage the <code>POST</code> requests (<code>FileUpload</code>).<br /> * * The servlet accepts commands sent in the following format:<br /> * <code>connector?Command=<FileUpload>&Type=<ResourceType>&CurrentFolder=<FolderPath></code> * with the file in the <code>POST</code> body.<br /> * <br> * It stores an uploaded file (renames a file if another exists with the * same name) and then returns the JavaScript callback. */ @SuppressWarnings("unchecked") public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.debug("Entering Connector#doPost"); response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); String commandStr = request.getParameter("Command"); String typeStr = request.getParameter("Type"); String currentFolderStr = request.getParameter("CurrentFolder"); logger.debug("Parameter Command: {}", commandStr); logger.debug("Parameter Type: {}", typeStr); logger.debug("Parameter CurrentFolder: {}", currentFolderStr); UploadResponse ur; // if this is a QuickUpload request, 'commandStr' and 'currentFolderStr' // are empty if (Utils.isEmpty(commandStr) && Utils.isEmpty(currentFolderStr)) { commandStr = "QuickUpload"; currentFolderStr = "/"; } if (!RequestCycleHandler.isEnabledForFileUpload(request)){ List prams = new ArrayList(); prams.add(UploadResponse.SC_SECURITY_ERROR); prams.add(null); prams.add(null); prams.add(Messages.NOT_AUTHORIZED_FOR_UPLOAD); ur = new UploadResponse(prams.toArray()); } else if (!CommandHandler.isValidForPost(commandStr)) { List prams = new ArrayList(); prams.add(UploadResponse.SC_ERROR); prams.add(null); prams.add(null); prams.add(Messages.INVALID_COMMAND); ur = new UploadResponse(prams.toArray()); } else if (typeStr != null && !ResourceTypeHandler.isValid(typeStr)){ List prams = new ArrayList(); prams.add(UploadResponse.SC_ERROR); prams.add(null); prams.add(null); prams.add(Messages.INVALID_TYPE); ur = new UploadResponse(prams.toArray()); } else if (!UtilsFile.isValidPath(currentFolderStr)) ur = UploadResponse.UR_INVALID_CURRENT_FOLDER; else { ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr); String typePath = UtilsFile.constructServerSidePath(request, resourceType); String typeDirPath = getServletContext().getRealPath(typePath); File typeDir = new File(typeDirPath); UtilsFile.checkDirAndCreate(typeDir); File currentDir = new File(typeDir, currentFolderStr); if (!currentDir.exists()) ur = UploadResponse.UR_INVALID_CURRENT_FOLDER; else { String newFilename = null; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); // 修改上传中文名乱码 upload.setHeaderEncoding("UTF-8"); // 完毕 try { List<FileItem> items = upload.parseRequest(request); // We upload only one file at the same time FileItem uplFile = items.get(0); String rawName = UtilsFile.sanitizeFileName(uplFile.getName()); String filename = FilenameUtils.getName(rawName); String baseName = FilenameUtils.removeExtension(filename); String extension = FilenameUtils.getExtension(filename); //修改上传文件名字,用UUID方法 // filename= UUID.randomUUID().toString()+ "."+ extension; // 完毕 //添加限制上传大小方法 //如果这个文件的扩展名不允许上传 if (!ExtensionsHandler.isAllowed(resourceType, extension)) { List prams = new ArrayList(); prams.add(UploadResponse.SC_INVALID_EXTENSION); ur = new UploadResponse(prams.toArray()); } //如果超出大小10M else if(uplFile.getSize()> 10000 * 1024) { List prams = new ArrayList(); prams.add(204); //传递一个自定义的错误码 ur = new UploadResponse(prams.toArray()); } // 如果不存在以上情况,则保存 else { // construct an unique file name File pathToSave = new File(currentDir, filename); int counter = 1; while (pathToSave.exists()) { newFilename = baseName.concat("(").concat(String.valueOf(counter)) .concat(")").concat(".").concat(extension); pathToSave = new File(currentDir, newFilename); counter++; } if (Utils.isEmpty(newFilename)) { List prams = new ArrayList(); prams.add(UploadResponse.SC_OK); prams.add(UtilsResponse.constructResponseUrl(request, resourceType, currentFolderStr, true, ConnectorHandler.isFullUrl()).concat(filename)); //传递一个自定义的错误码 ur = new UploadResponse(prams.toArray()); } else { List prams = new ArrayList(); prams.add(UploadResponse.SC_RENAMED); prams.add(UtilsResponse.constructResponseUrl(request, resourceType, currentFolderStr, true, ConnectorHandler.isFullUrl()).concat(newFilename)); prams.add(newFilename); ur = new UploadResponse(prams.toArray()); } // secure image check if (resourceType.equals(ResourceTypeHandler.IMAGE) && ConnectorHandler.isSecureImageUploads()) { if (UtilsFile.isImage(uplFile.getInputStream())) uplFile.write(pathToSave); else { uplFile.delete(); List prams = new ArrayList(); prams.add(UploadResponse.SC_INVALID_EXTENSION); ur = new UploadResponse(prams.toArray()); } } else uplFile.write(pathToSave); } } catch (Exception e) { List prams = new ArrayList(); prams.add(UploadResponse.SC_SECURITY_ERROR); ur = new UploadResponse(prams.toArray()); } } } out.print(ur); out.flush(); out.close(); logger.debug("Exiting Connector#doPost"); } }
Web.xml加入以下代码
<servlet> <servlet-name>Connector</servlet-name> <servlet-class> com.xx.fckeditor.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> <url-pattern> /fckeditor/editor/filemanager/connectors/* </url-pattern> </servlet-mapping>
Jsp页面中头部加入
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
使用FCK的标签调用
<td>新闻内容:</td> <td><FCK:editor instanceName="content" value="${articleForm.content}" height="400" width="680"> </FCK:editor></td>
最后需要在TOMCAT的server.xml中加入URIEncoding="UTF-8",就完成了
附件中是教我的一个朋友 写的DEMO,共享咯
- fck.rar (1.5 MB)
- 下载次数: 25
相关推荐
本文将详细介绍FCKeditor2.6.4的使用方法,帮助开发者和用户更好地理解和操作这个编辑器。 1. **安装与集成** - 下载FCKeditor2.6.4压缩包,解压后将文件夹上传至服务器或本地项目目录。 - 在需要使用编辑器的...
本文将详细介绍如何在 JSP 应用程序中安装、配置并使用 FCKeditor 2.6.4。 #### 1. 下载 FCKeditor 首先,需要下载 FCKeditor 以及其 Java 支持包: - **FCKeditor 2.6.4**: 可以通过地址 ...
**在ASP中配置FCKeditor 2.6.4** 1. **下载与解压**:首先,你需要从官方网站或可靠的源获取FCKeditor 2.6.4的压缩包,并将其解压到服务器的合适目录下。文件列表中包含的“fckeditor”文件夹即是编辑器的核心组件...
包括fckeditor2.6.4+fckeditor-java-2.4.1配置所需资源包及fckeditor-java-2.4.1源码和配置说明文档。 配置中解决了中文乱码,并为上传文件自动创建日期文件夹。
在提供的压缩包文件中,"说明.htm"可能包含了关于如何安装、配置和使用Fckeditor2.6.4增强版的详细指导,包括图片热区和上传文件的具体操作方法。"readme.txt"通常是开发者或发布者提供的简要说明或注意事项,可能...
以下将详细介绍如何在ASP.NET项目中安装并配置FCKeditor 2.6.4版本。 **一、下载与解压** 首先,你需要从官方网站或者第三方资源网站下载FCKeditor的最新2.6.4版本。下载完成后,解压缩到本地文件夹,通常包含一个...
ASP FCKeditor 2.6.4是一款专为ASP(Active Server Pages)平台设计的开源富文本编辑器,它在Web开发中广泛用于创建...总之,ASP FCKeditor 2.6.4是一款强大的工具,为ASP平台的Web内容管理提供了便捷高效的解决方案。
- **fckeditor**:这个文件夹包含了FCKeditor的所有核心文件,如JavaScript库、CSS样式表、图片资源和语言文件。这些文件是编辑器运行所必需的。 - **userfiles**:这是FCKeditor默认的用户文件存储目录,用于存放...
要在JSP项目中使用FCKeditor,首先需要下载并解压压缩包,然后将FCKeditor的文件夹放到Web应用的适当目录下。接着,在JSP页面中引入FCKeditor的JavaScript文件,并通过JavaScript调用来实例化编辑器。最后,配置...
FCKeditor 2.6.4是其在2008年发布的一个稳定版本,据描述所示,它在实际应用中表现出良好的性能和可用性。 FCKeditor的核心特性包括: 1. **所见即所得(WYSIWYG)编辑**:用户在网页上直接进行文本编辑,看到的...
3. **丰富的编辑功能**:FCKeditor提供了许多高级编辑功能,如字体样式调整、段落格式设置、颜色选择、链接管理、图片上传、表格编辑、嵌入多媒体内容等。 4. **自定义扩展**:开发者可以通过API和插件系统对...
2. 解压缩fckeditor_2.6.4.zip,将解压出的`fckeditor`文件夹复制到Web工程的WebRoot目录下。该文件夹内包含了`editor`子目录,以及fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml和fckpackager.xml...
2. 解压缩fckeditor_2.6.4.zip,将解压后的fckeditor文件夹复制到WebRoot目录下。fckeditor目录内包含了editor子目录,以及fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml和fckpackager.xml等关键...
假设FCKeditor和调用脚本位于同一目录内,FCKeditor的文件夹应包含整个2.6.4版本的程序文件。 2. **整合JSP包**:解压名为“FCKeditor-2.3.zip”的JSP整合包,其主要目的是简化在Java服务器页面中使用FCKeditor的...
以下是对 fckeditor 配置和使用的详细介绍: ### 1. 下载与安装 首先,访问 fckeditor 的官方网站(http://www.fckeditor.net)下载最新版本。在本文案例中,下载的是 2.6.4 版本。下载完成后,将压缩包解压,并将...