错误:

文件名格式不对:未命??.jpg

SmartUpload mySmartUpload = new SmartUpload();

com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);

myFileName = new String(myFile.getFileName().getBytes("gbk"),"utf-8");

寻找原因历程:

1、尝试了上传几个不同的文件,发现文件名%2==0的时候,文件名不会出现最后一个中文变成??的情况

猜想是编码格式的问题:于是包括jsp,js,request,response的编码格式统统都设置为utf-8。后来发现还是没有任何效果。

猜想可能是ext的FormPanel组建的原因。

2、在js界面获取FormPanel的绝对路径:Ext.getCmp('loadfile').getValue();(loadfile是组建FormPanel的id)没有出现乱码

原因那应该就是JSPSmart这个jar包本身的bug了。

解决方法:

1. 在servlet将上传文件进行重命名,这样就可以避免文件名乱码的问题。但是有些情况是必须使用原来的文件名的,这个方法就无法解决文艺了。

2. 对SmartUpload进行反编译,修改代码。这个百度上很多。

3. 据说这个是SmartUpload的一个Bug,所以可以关注官网更新jar包。不过如果其他同事也用这个jar,不知道升级后会他们会不会有影响,所以他们不给我升级。

虽然姐觉得一般升级不会对原来的版本影响的,难道使用jdk7会造成jdk2的影响?

4. 据说这个SmartUpload在上传大文件类型的时候也有bug,建议使用Commons FileUpload

5. 在前端页面也就是ext的FormPanel summit的时候截取文件名作为参数传递到后台,后台就不需要用SmartUpload本身的方法去获取文件名,这样可以避免文件名的乱码。

@ js端截取文件名并通过url传参到后台:

  var urlStr = Ext.getCmp('loadfile').getValue();
      var fileName = urlStr.substring(urlStr.lastIndexOf("\\")+1,urlStr.lastIndexOf("."));

  form.form.submit({
                            url : '/AdjustServlet?action=upload&slid='+slid+'&fileName='+fileName,
                             method : 'POST',
                             waitMsg: '正在上传...',
                             success : function() {                    
                                 //list();
                                 Ext.Msg.alert('Message','上传成功!');                         
                                 win.close();                         
                             },
                             failure : function() {
                                 Ext.Msg.alert('Error','上传失败.');
                             }
                         });

@ 后台接收文件名并且用方法获取后缀名,扩展名=文件名+"."+后缀名

  String fileName = new String(request.getParameter("fileName").getBytes("iso-8859-1"),"utf-8");

  String suffix = myFile.getFileExt();

  myFileName.append(fileName).append(".").append(suffix);

这个方法就可以解决文件名中文为基数位乱码了。

exjs上传图片异常:com.jspsmart.upload.SmartUploadException: File can't be saved (1120).的更多相关文章

  1. How to upload a file in MVC4

    Uploading a file in Asp.Net MVC application is very easy. The posted file is automatically available ...

  2. axios upload excel file

    axios upload excel file https://github.com/axios/axios/issues/1660 https://stackoverflow.com/questio ...

  3. fetch & form-data & upload & image file

    fetch & form-data & upload & image file no need multipart/form-data https://blog.xinshan ...

  4. 上传图片预览JS脚本 Input file图片预览的实现示例

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. jquery ajax发送delete(use in jquery file upload delete file)

    环境: jQuery file upload HTML example code <div class="pic-preview"> <div class=&qu ...

  6. [MODx] Solve cannot upload large file

    If you also run into this problem, dont' worry, here is the solution for you. First: In Modx, go &qu ...

  7. iOS上传图片和视频(base64和file)

    前言:iOS开发中经常会使用到图片和视频上传及保存到相册,下面我讲介绍视频图片的两种上传服务器的方法.以阿里云的OSS服务器为例. 友情提示:上传图片方法在APP中使用很广泛,最好单独写一个图片上传的 ...

  8. Upload a file with $.ajax to AWS S3 with a pre-signed url

    转载自:https://gist.github.com/guumaster/9f18204aca2bd6c71a24 生成预签名的Demo文档:https://docs.aws.amazon.com/ ...

  9. troubleshooting-执行导数shell脚本抛异常error=2, No such file or directory

    Cannot run program "order_log.sh" (in directory "/data/yarn/nm/usercache/chenweidong/ ...

随机推荐

  1. Centos7 安装keepalived实现高可用

    场景:尝试安装keepalived实现高可用,进而在suse环境中部署. 测试过程需要配合Nginx的相关知识:Centos7 Nginx安装 1 安装过程 问题 !!! OpenSSL is not ...

  2. vue数据驱动作用域问题

    需求是这样的,如图 点击禁用后,变成启用,但是结果却不让人满意 我们先来看一下错误代码: //conponet控件里的内容 html内容: <div> <button @click. ...

  3. tomcat的常用配置方法

    1.tomcat配置某个站点的欢迎页面的方法 2.tomcat配置虚拟目录的方法 3.tomcat配置虚拟主机的方法

  4. Java第三次上课课堂试验博文

    1.Java字段初始化的规律: 运行如下所示的代码 package demo; public class InitializeBlockDemo { /** * @param args */ publ ...

  5. 18. leetcode 387. First Unique Character in a String

    Given a string, find the first non-repeating character in it and return it's index. If it doesn't ex ...

  6. spring mvc4使用及json 日期转换解决方案

    spring mvc使用注解方式配制,以及对rest风格的支持,真是完美致极.下面将这两天研究到的问题做个总结,供参考.1.request对象的获取方式1:在controller方法上加入reques ...

  7. JDBC连接数据库的基本步骤

    第一步:注册驱动==>:Class.forName("数据库驱动的完整名称(mysql的数据库驱动名称:com.mysql.jbdc.Driver)"); 第二步:创建一个数 ...

  8. C#使用Xamarin开发可移植移动应用(1.入门与Xamarin.Forms页面),附源码

    前言 什么是Xamarin? Xamarin始创于2011年,旨在使移动开发变得难以置信地迅捷和简单. Xamarin的产品简化了针对多种平台的应用开发,包括iOS.Android.Windows P ...

  9. eclipse导入lombok后打不开(如果你的lombok不是最新的,那就来下载最新的)

    如果你的不是最新的,去这里下载最新版的,先点击左上角的Download红方块,然后再点击下图中的位置 https://projectlombok.org/ 下载完后把eclipse关掉,双击下载的ja ...

  10. JBOSS安装配置详细教程

    首先在http://jbossas.jboss.org/downloads/下载相关程序我下载的是 JBoss AS 6.1.0.Final 1.配置jboss环境 1.1用户变量path后面添加 ; ...