package cn.itcast.down.utils;
import java.io.IOException;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import sun.misc.BASE64Encoder;
/*
* 下载文件的工具类
*/
public class DownUtils {
public static String filenameEncoding(String filename,
HttpServletRequest request) throws IOException{
String agent=request.getHeader("User-Agent");//获取浏览器
if(agent.contains("Firefox")){
BASE64Encoder base64Encoder=new BASE64Encoder();
filename="=?utf-8?B?"+base64Encoder.encode(filename.getBytes("utf-8"))
+"?=";
}else if(agent.contains("MSIE")){
filename=URLEncoder.encode(filename,"utf-8");
}else{
filename=URLEncoder.encode(filename, "utf-8");
}
return filename;
}
}
原文地址:https://www.cnblogs.com/xiqoqu/p/9194683.html
时间: 2024-11-09 05:17:05