错误:

文件名格式不对:未命??.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. LeetCode-Best Time to Buy and Sell Stock III[dp]

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  2. 正则替换内容中图片的src

    string test = "<IMG src=\"http://www.baidu.com/upload/2009_11/09112110144808.jpg\" ...

  3. R读取MySQL数据出现乱码,解决该问题的方法总结

    最终的解决办法直接看 4 我的思路: 我用的都是utf-8编码,电脑系统win7, MySQL-Front进行数据库的可视化. 1.我用的是RStudio,先去设置R的默认编码: Tools→Glob ...

  4. 斗地主[NOIP2015]

    题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3<4< ...

  5. git入门(3)git checkout 和git branch分支的创建和删除

    在一个项目中,需要多人同时开发,协同coding 要求: 开发时请用开发分支daily/0.0.1, 禁止直接使用master分支开发新建分支 git checkout -b daily/0.0.1 ...

  6. PyCharm 去掉自动保存功能

    PyCharm 4.5.4 环境配置 1.去掉"自动保存功能" pycharm默认是自动保存的,习惯自己按 ctrl + s 的可以进行如下设置: 菜单File -> Set ...

  7. spring集成mybatis实现mysql读写分离

    前言 在网站的用户达到一定规模后,数据库因为负载压力过高而成为网站的瓶颈.幸运的是目前大部分的主流数据库都提供主从热备功能,通过配置两台数据库主从关系,可以将一台数据库的数据更新同步到另一台服务器上. ...

  8. Spring+SpringMVC+MyBatis+easyUI整合

    进阶篇 Spring+SpringMVC+MyBatis+easyUI整合进阶篇(一)设计一套好的RESTful API 优化篇 Spring+SpringMVC+MyBatis+easyUI整合优化 ...

  9. C#委托和事件?策略模式?接口回调?还不清楚的赶紧来看我扯

    早前学习委托的时候,写过一点东西,今天带着新的思考和认知,再记点东西.这篇文章扯到设计模式中的策略模式,观察者模式,还有.NET的特性之一--委托.真的,请相信我,我只是在扯淡...... 场景练习 ...

  10. 【NO.3-1】Jmeter - 在Windows配置HOSTS的方法

    在Windows配置HOSTS 那么还记得Windows如何修改HOSTS文件吗? (1) 进入到C:\Windows\System32\drivers\etc (2) 通过”记事本”来打开hosts ...