FCKeditor中文文件上传乱码解决方案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

FCKeditor文件上传乱码解决方案1.找到Connector找到ConnectorServlet,千万不要弄错了,不是FCKeditor-2.3.jar当中的ConnectorServlet,而是java-core-2.4.1.jar中的,net.fckeditor.connector.ConnectorServlet文件夹下找到ConnectorServlet,反编译,并修正错误。2.修改web.xml在web.xml中声明ConnectorServlet,如下,这个就是图片上传的Servlet方法,反编译后的ConnectorServlet可自行选择包来放置3.增加fckeditor.properties创建fckeditor.properties文件在你的src目录下面,并且添加以下内容,分别对应“路径”,“方法”以及“FLASH支持格式”4.解决上传中文名出现乱码问题在ConnectorServlet找到这行在下面添加upload.setHeaderEncoding(UTF-8);这句即可(图片中已经是添加过后正确的写法)5.解决创建中文名的目录时会出现乱码修改tomcat的server.xml配置如图所示,在后面加上URIEncoding=”UTF-8”即可在ConnectorServlet中找到newFolderStr,对其进行编码转换,如下所示即可6.解决引用的中文名字的图片不能正常显示在ConnectorServlet中找到filename,获取到后缀之后只要用UUID来对其重命名即可,如下所示即可以上即为解决Fckeditor图片中文出现乱码问题的解决方案。-------------------------------------------------------------附上更正后的ConnectorServlet源代码-------------------------------------------------------------packagecom.telehot.fckeditor.connector;importjava.io.File;importjava.io.IOException;importjava.io.PrintWriter;importjava.util.List;importjava.util.UUID;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importnet.fckeditor.handlers.CommandHandler;importnet.fckeditor.handlers.ConnectorHandler;importnet.fckeditor.handlers.ExtensionsHandler;importnet.fckeditor.handlers.RequestCycleHandler;importnet.fckeditor.handlers.ResourceTypeHandler;importnet.fckeditor.response.UploadResponse;importnet.fckeditor.response.XmlResponse;importnet.fckeditor.tool.Utils;importnet.fckeditor.tool.UtilsFile;importnet.fckeditor.tool.UtilsResponse;importorg.apache.commons.fileupload.FileItem;importorg.apache.commons.fileupload.FileItemFactory;importorg.apache.commons.fileupload.disk.DiskFileItemFactory;importorg.apache.commons.fileupload.servlet.ServletFileUpload;importorg.apache.commons.io.FilenameUtils;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;publicclassConnectorServletextendsHttpServlet{privatestaticfinallongserialVersionUID=-5742008970929377161L;privatestaticfinalLoggerlogger=LoggerFactory.getLogger(ConnectorServlet.class);publicvoidinit()throwsServletException,IllegalArgumentException{StringrealDefaultUserFilesPath=getServletContext().getRealPath(ConnectorHandler.getDefaultUserFilesPath());FiledefaultUserFilesDir=newFile(realDefaultUserFilesPath);UtilsFile.checkDirAndCreate(defaultUserFilesDir);logger.info(ConnectorServletsuccessfullyinitialized!);}publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{logger.debug(EnteringConnectorServlet#doGet);response.setCharacterEncoding(UTF-8);response.setContentType(application/xml;charset=UTF-8);response.setHeader(Cache-Control,no-cache);PrintWriterout=response.getWriter();StringcommandStr=request.getParameter(Command);StringtypeStr=request.getParameter(Type);StringcurrentFolderStr=request.getParameter(CurrentFolder);logger.debug(ParameterCommand:{},commandStr);logger.debug(ParameterType:{},typeStr);logger.debug(ParameterCurrentFolder:{},currentFolderStr);XmlResponsexr;if(!RequestCycleHandler.isEnabledForFileBrowsing(request)){xr=newXmlResponse(1,Thecurrentuserisn'tauthorizedforfilebrowsing!);}else{if(!CommandHandler.isValidForGet(commandStr)){xr=newXmlResponse(1,Invalidcommandspecified);}else{if((typeStr!=null)&&(!ResourceTypeHandler.isValid(typeStr))){xr=newXmlResponse(1,Invalidresourcetypespecified);}else{if(!UtilsFile.isValidPath(currentFolderStr)){xr=newXmlResponse(1,Invalidcurrentfolderspecified);}else{CommandHandlercommand=CommandHandler.getCommand(commandStr);ResourceTypeHandlerresourceType=ResourceTypeHandler.getDefaultResourceType(typeStr);StringtypePath=UtilsFile.constructServerSidePath(request,resourceType);StringtypeDirPath=getServletContext().getRealPath(typePath);FiletypeDir=newFile(typeDirPath);UtilsFile.checkDirAndCreate(typeDir);FilecurrentDir=newFile(typeDir,currentFolderStr);if(!currentDir.exists()){xr=newXmlResponse(102);}else{xr=newXmlResponse(command,resourceType,currentFolderStr,UtilsResponse.constructResponseUrl(request,resourceType,currentFolderStr,true,ConnectorHandler.isFullUrl()));if(command.equals(CommandHandler.GET_FOLDERS)){xr.setFolders(currentDir);}elseif(command.equals(CommandHandler.GET_FOLDERS_AND_FILES)){xr.setFoldersAndFiles(currentDir);}elseif(command.equals(CommandHandler.CREATE_FOLDER)){StringtempStr=request.getParameter(NewFolderName);tempStr=newString(tempStr.getBytes(ISO8859-1),UTF-8);StringnewFolderStr=UtilsFile.sanitizeFolderName(tempStr);logger.debug(ParameterNewFolderName:{},newFolderStr);FilenewFolder=newFile(currentDir,newFolderStr);interrorNumber=110;if(newFolder.exists())errorNumber=101;else{try{errorNumber=newFolder.mkdir()?0:102;}catch(SecurityExceptione){errorNumber=103;}}xr.setError(errorNumber);}}}}}}out.print(xr);out.flush();out.close();logger.debug(ExitingConnectorServlet#doGet);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{logger.debug(EnteringConnector#doPost);respo

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功