Fckeditor 文件名乱码解决一法
来源:互联网 发布:javascript有类吗 编辑:程序博客网 时间:2024/05/21 21:45
<script type="text/javascript"><!--google_ad_client = "pub-9528830580198364";/* 文章顶部广告(方框)300*250 */google_ad_slot = "0068799835";google_ad_width = 300;google_ad_height = 250;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>Fckeditor的乱码太经典了,这里说以下Fckeditor提交文件后,浏览器浏览时文件名是乱码,没法识别中文文件名的解决方法
其实最理想的方法是让服务器Tomcat识别中文文件名,这里我的尝试没有成功
我是把上传的文件名改成以数字为名字的文件,文件命名为随即数字,以时间为种子
connectorServlet.java
部分代码
SimpleUploaderServlet.java
其实最理想的方法是让服务器Tomcat识别中文文件名,这里我的尝试没有成功
我是把上传的文件名改成以数字为名字的文件,文件命名为随即数字,以时间为种子
connectorServlet.java
部分代码
- if(!commandStr.equals("FileUpload"))
- retVal="203";
- else {
- DiskFileUpload upload = new DiskFileUpload();
- upload.setHeaderEncoding("utf-8");
- try {
- List items = upload.parseRequest(request);
- Map fields=new HashMap();
- Iterator iter = items.iterator();
- while (iter.hasNext()) {
- FileItem item = (FileItem) iter.next();
- if (item.isFormField())
- fields.put(item.getFieldName(),item.getString());
- else
- fields.put(item.getFieldName(),item);
- }
- FileItem uplFile=(FileItem)fields.get("NewFile");
- String fileNameLong=uplFile.getName();
- fileNameLong=fileNameLong.replace('//','/');
- String[] pathParts=fileNameLong.split("/");
- String fileName=pathParts[pathParts.length-1];
- // String nameWithoutExt=getNameWithoutExtension(fileName);
- String ext=getExtension(fileName);
- //随机数命名文件
- Date date=new Date();
- Random rand=new Random(date.getTime());
- String tempFileName=rand.nextInt()+"."+ext;
- File pathToSave=new File(currentDirPath,tempFileName);
- int counter=1;
- while(pathToSave.exists()){
- newName=tempFileName+"("+counter+")"+"."+ext;
- retVal="201";
- pathToSave=new File(currentDirPath,newName);
- counter++;
- }
- uplFile.write(pathToSave);
- }catch (Exception ex) {
- retVal="203";
- }
- }
- if(enabled) {
- DiskFileUpload upload = new DiskFileUpload();
- upload.setHeaderEncoding("utf-8");
- try {
- List items = upload.parseRequest(request);
- Map fields=new HashMap();
- Iterator iter = items.iterator();
- while (iter.hasNext()) {
- FileItem item = (FileItem) iter.next();
- if (item.isFormField())
- fields.put(item.getFieldName(),item.getString());
- else
- fields.put(item.getFieldName(),item);
- }
- FileItem uplFile=(FileItem)fields.get("NewFile");
- String fileNameLong=uplFile.getName();
- fileNameLong=fileNameLong.replace('//','/');
- String[] pathParts=fileNameLong.split("/");
- String fileName=pathParts[pathParts.length-1];
- // String nameWithoutExt=getNameWithoutExtension(fileName);
- String ext=getExtension(fileName);
- //随机数命名文件
- Date date=new Date();
- Random rand=new Random(date.getTime());
- String tempFileName=rand.nextInt()+"."+ext;
- File pathToSave=new File(currentDirPath,tempFileName);
- fileUrl=currentPath+"/"+tempFileName;
- if(extIsAllowed(typeStr,ext)) {
- int counter=1;
- while(pathToSave.exists()){
- newName=tempFileName+"("+counter+")"+"."+ext;
- fileUrl=currentPath+"/"+newName;
- retVal="201";
- pathToSave=new File(currentDirPath,newName);
- counter++;
- }
- uplFile.write(pathToSave);
- }
- else {
- retVal="202";
- errorMessage="";
- if (debug) System.out.println("Invalid file type: " + ext);
- }
- }catch (Exception ex) {
- if (debug) ex.printStackTrace();
- retVal="203";
- }
- }
- else {
- retVal="1";
- errorMessage="This file uploader is disabled. Please check the WEB-INF/web.xml file";
- }
- Fckeditor 文件名乱码解决一法
- FCKeditor乱码一解(解决<会被转换为实体)
- 解决中文文件名乱码
- 文件名 乱码终极解决
- 解决下载文件名乱码
- linux解决文件名乱码
- 上传文件名乱码的解决
- Banshee中文文件名乱码解决
- 解决windows文件名乱码问题
- 解决Firefox下载文件名乱码
- FCKeditor for Java 中文文件名文件上传乱码问题
- FCKeditor在线编辑器解决中文乱码办法
- Fckeditor解决上传中文名称图片出现乱码
- 解决PHP下载文件名中文解决乱码
- 附件下载,中文文件名乱码如何解决???
- 跨平台中文文件名乱码的解决
- 跨平台中文文件名乱码的解决
- 解决php读中文目录、文件名乱码
- 第四课 JBPM简单实例入门
- 连接池的基本工作原理
- 近期PHP二三事儿
- 提高自己JAVA水平的十大技术讨论
- WIN/CAMEL - introduction
- Fckeditor 文件名乱码解决一法
- 命令别人的十句话
- 物料编码原则---by AMT
- Linux/Unix环境下的make和makefile详解
- variant 中的困惑
- 问题解决: vs2008 fatal error LNK1104: 无法打开文件 libcpmtd.lib
- 字符串函数详解
- C++中的虚函数
- Java中数据库连接池原理机制的详细讲解