日期:2014-05-18  浏览次数:20656 次

上传文件名的乱码问题
用jspSmart上传文件时,如果文件名中有中文,上传后显示的文件名变成了乱码,在网上找了几个自称修改了源代码后能解决乱码问题的jar包,可是还是没能解决文件名乱码问题,哪位大侠能指点一下?

------解决方案--------------------
直接将上传的文件名转存为:
Java code

String ext = myFile.getFileExt(); // 取得后缀名
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
Date dt = new Date(System.currentTimeMillis()); 

String filename =fmt.format(dt);
saveurl = request.getRealPath("\\")+"file\\";
                    
saveurl +=filename + "." + ext;// 最终文件的保存路径
String name= filename + "." + ext;

------解决方案--------------------
LZ参考下吧,
有很多方法值得看下
http://topic.csdn.net/u/20081225/15/7f53258e-4543-4802-8fe5-6ff7033bf9b1.html
------解决方案--------------------
重新命名上传的文件
// 重命名文件
@SuppressWarnings("static-access")
private String renameFile() {
String t = new Timestamp(new Date().getTime()).toString();
t = t.replaceAll("-", "");
t = t.replaceAll(":", "");
t = t.replace(".", "");
t = t.replaceAll(" ", "");
Random rd = new Random();
int rdNum = rd.nextInt(Integer.MAX_VALUE);
return (t + rdNum);
}
------解决方案--------------------
如果你的文件名是从别的地方或页面传递过来的你就将文件名编码:
Java code
fileName = URLEncoder.encode(fileName,"GBK");