FCKeditor配置.doc_第1页
FCKeditor配置.doc_第2页
FCKeditor配置.doc_第3页
FCKeditor配置.doc_第4页
FCKeditor配置.doc_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1.FCKeditor2.4集成在SSH框架中,在web.xml中要加入以下配置 Connector /*根据自己的项目路径导入ConnectorServlet.class*/com.qian.menu.article.action.ConnectorServlet baseDir/UserFiles/1Connector/js/fckeditor/editor/filemanager/connectors/* 2如果使用的struts2进行项目开发的话,你会发现当上传文件时会出现 “Error on file upload. Error number:203”的错误提示。这是因为fck与struts2框架不兼容,struts2转发了fck的servlet。 解决办法:在web.xml中修改struts2的filter-mapping Java代码 struts2 /* 修改成 struts2 *.action *.jsp 如果还有其他url映射也可以添加到filter-mapping中去。 3.使用fck创建中文文件夹出现乱码问题 找到ConnectorServlet.class文件在用一个fck的源文件版本要与框架中的版本一致然后打开复制出ConnectorServlet.java中的全部代码,自己在新建一个与 ConnectorServlet同名的类,在doGet方法中找String newFolderStr =utilesFile.sanitizeFolderName(request.getParameter(“NewFolderName”);把request.getParameter(“NewFolderName”)剪切出来,自定义一个String 型的 temp String Temp = request.getParameter(“NewFolderName”);Temp = new String(Temp.getBytes(“iso8859-1”),”UTF-8”);在将Temp放入sanitizeFolderName()中即可,一般情况下在ConnectorServlet.java中已经写好了。3导入配置文件用来存放图片4.导入4个jar包5.在struts.xml文件中加入interceptor-ref name=defaultStack image/bmp,image/png,image/gif,image/jpeg,image/jpg ,image/x-png, image/pjpeg 1048576/* * 类名称 ConnectorServlet.java * Description:填写文件作用简要说明 * Version :1.0 * 作者: 王兆来 * 创建日期: 2010-10-29 * Copyright: 奇安科技发展有限公司 版权所有 */import javax.servlet.http.HttpServlet;import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import java.util.UUID; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.fckeditor.connector.Messages; import net.fckeditor.handlers.CommandHandler; import net.fckeditor.handlers.ConnectorHandler; import net.fckeditor.handlers.ExtensionsHandler; import net.fckeditor.handlers.RequestCycleHandler; import net.fckeditor.handlers.ResourceTypeHandler; import net.fckeditor.response.UploadResponse; import net.fckeditor.response.XmlResponse; import net.fckeditor.tool.Utils; import net.fckeditor.tool.UtilsFile; import net.fckeditor.tool.UtilsResponse; import mons.fileupload.FileItem; import mons.fileupload.FileItemFactory; import mons.fileupload.disk.DiskFileItemFactory; import mons.fileupload.servlet.ServletFileUpload; import mons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ConnectorServlet extends HttpServlet private static final long serialVersionUID = -5742008970929377161L; private static final Logger logger = LoggerFactory .getLogger(ConnectorServlet.class); /* * Initialize the servlet: mkdir <DefaultUserFilesPath> */ public void init() throws ServletException, IllegalArgumentException String realDefaultUserFilesPath = getServletContext().getRealPath( ConnectorHandler.getDefaultUserFilesPath(); File defaultUserFilesDir = new File(realDefaultUserFilesPath); UtilsFile.checkDirAndCreate(defaultUserFilesDir); (ConnectorServlet successfully initialized!); /* * Manage the GET requests (GetFolders, * GetFoldersAndFiles, CreateFolder). * * The servlet accepts commands sent in the following format: * connector?Command=<CommandName>&Type=<ResourceType>&CurrentFolder=<FolderPath> * * It executes the commands and then returns the result to the client in XML * format. * */ 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 fileName = request.getParameter(NewFolderName); fileName = new String(fileName.getBytes(iso8859-1),UTF-8); String newFolderStr = UtilsFile.sanitizeFolderName(fileName); 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 POST requests (FileUpload). * * The servlet accepts commands sent in the following format: * connector?Command=<FileUpload>&Type=<ResourceType>&CurrentFolder=<FolderPath> * with the file in the POST body. * * 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 = null; Object obj = new Object4; / 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) obj0 = UploadResponse.SC_SECURITY_ERROR; obj1 = null; obj2 = null; obj3 = Messages.NOT_AUTHORIZED_FOR_UPLOAD; ur = new UploadResponse(obj); else if (!CommandHandler.isValidForPost(commandStr) obj0 = UploadResponse.SC_ERROR; obj1 = null; obj2 = null; obj3 = Messages.INVALID_COMMAND; ur = new UploadResponse(obj); else if (typeStr != null & !ResourceTypeHandler.isValid(typeStr) obj0 = UploadResponse.SC_ERROR; obj1 = null; obj2 = null; obj3 = Messages.INVALID_TYPE; ur = new UploadResponse(obj); 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 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); filename = UUID.randomUUID().toString()+.+extension; if (!ExtensionsHandler.isAllowed(resourceType, extension) obj0 = UploadResponse.SC_INVALID_EXTENSION; obj1 = null; obj2 = null; obj3 = null; ur = new UploadResponse(obj); else if(uplFile.getSize()10*1024*1024) obj0 = 333; obj1 = null; obj2 = null; obj3 = null; ur = new UploadResponse(obj); 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

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论