日期:2014-05-19  浏览次数:20616 次

j2ee 下载文件 中文文件名乱码

post请求,文件名中文乱码(非英文)解决方法

response.setContentType("application/octet-stream; charset=UTF-8");						
if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0){            	
    //IE
    fileName = URLEncoder.encode(fileName, "UTF-8");            
}else if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0) {
    //firefox
    fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");            
}else{            	
    // other       	
    fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");            
}						
response.setHeader("Content-Disposition", "attachment; filename=\""+ fileName + "\"");

?

?