您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

java下载的文件名乱码

2024/3/9 4:38:31发布25次查看
java下载的文件名乱码    
java文件下载时乱码有两种情况:
1,下载时中文文件名乱码
2,下载时因为路径中包含中文文件名乱码,提示找不到文件
解决方法见下面部分代码(推荐教程:java教程)
response.setcontenttype("multipart/form-data"); string useragent = request.getheader("user-agent"); string orafilename = meetingfile.getfilename(); string formfilename=orafilename; // 针对ie或者以ie为内核的浏览器: if (useragent.contains("msie") || useragent.contains("trident")) { formfilename = java.net.urlencoder.encode(formfilename, "utf-8"); } else { // 非ie浏览器的处理: formfilename = new string(formfilename.getbytes("utf-8"), "iso-8859-1"); } response.setheader("content-disposition", string.format("attachment; filename=\"%s\"", formfilename)); response.setcontenttype("application/vnd.ms-excel;charset=utf-8"); response.setcharacterencoding("utf-8"); servletoutputstream out; // 通过文件路径获得file对象 file file = null; if (meetingfile != null) { file = new file(path + "upload/"+orafilename); }
(1)如果第一种乱码类型,下载页面遇到以下的中文乱码问题
用以下代码解决
(2)如果下载遇到第二种乱码问题,如图:
用以下代码解决:即首先确保tomcat ,eclipse等为utf-8编码
然后java中这样与第一种对文件名编码分开,使它们分别编码,互不影响。
以上就是java下载的文件名乱码的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product