Newer
Older
package com.cesgroup.bdc.util;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class DownloadUtil {
public static String getContentDisposition(HttpServletRequest request, String fileName) throws UnsupportedEncodingException {
String contentDisposition = null;
String userAgent = request.getHeader("User-Agent");
if (userAgent.toLowerCase().indexOf("firefox") > -1) {
String ss = URLEncoder.encode(fileName, "UTF-8");
contentDisposition = "attachment;filename*=UTF-8'zh_cn'" + ss;
} else {
String ss = new String(fileName.getBytes("GBK"), "ISO-8859-1");
contentDisposition = "attachment;filename=" + ss;
}
return contentDisposition;
}
}