文件下载时文件名在ie和firefox下面表现不一致问题
转自:http://www.iteye.com/topic/50414
private String processFileName(String fileName,String agent) throws IOException{String codedfilename = null;if (null != agent && -1 != agent.indexOf("MSIE")){ String prefix = fileName.lastIndexOf(".")!=-1?fileName.substring(0,fileName.lastIndexOf(".")):fileName;String extension = fileName.lastIndexOf(".")!=-1?fileName.substring(fileName.lastIndexOf(".")):"";String name = java.net.URLEncoder.encode(fileName, "UTF8"); if(name.lastIndexOf("%0A")!=-1){name = name.substring(0,name.length()-3);} int limit = 150 - extension.length(); if (name.length() > limit) { name = java.net.URLEncoder.encode(prefix.substring(0, Math.min(prefix.length(), limit / 9)), "UTF-8"); if(name.lastIndexOf("%0A")!=-1){name = name.substring(0,name.length()-3);} } codedfilename = name + extension; } else if (null != agent && -1 != agent.indexOf("Mozilla")) { codedfilename = "=?UTF-8?B?"+(new String(org.apache.commons.codec.binary.Base64.encodeBase64(fileName.getBytes("UTF-8"))))+"?=";}else { codedfilename = fileName;} return codedfilename;}