/** * Desc: Download Tool class * @date 2014-6-26/public class Downloadutil {/** * Desc: According to the file header to determine the request from the browser, so that the targeted file name transcoding * @dat E 2014-6-26 * @param request * @return * @throws Exception/public static string Transfilename (String fileName
, HttpServletRequest request) {String Agent = Request.getheader ("user-agent"); FileName = Filename.trim ();
Go to the end of the space try {////According to the file header to judge the request from the browser so that the targeted file name transcoding if (null!= agent &&-1!= agent.indexof ("TheWorld")) {//window of the world FileName = new String (filename.getbytes ("gb2312"), "iso8859-1"); Resolves the downloaded file name containing the parentheses convert%28%29}else if (null!= agent &&-1!= agent.indexof ("MSIE 8.0")) {//IE8 String lenfile
Name = Urlencoder.encode (FileName, "UTF-8"); if (Lenfilename.length () > 150) {//filename length is greater than 150 characters filename = new String (filename.getbytes ("gb2312"), "Iso8859-1"
);
else {filename = urlencoder.encode (filename, "UTF-8"). Replace ("+", "%20"); }}else if (null!= agent &&-1!= Agent.indexoF ("MSIE 7.0") &&-1!= agent.indexof ("SE 2.X METASR 1.0")) {//sogo Browser filename = urlencoder.encode (filename, "U
TF-8 "). Replace (" + ","%20 "); }else if (null!= agent && ( -1!= agent.indexof ("SV1") | |-1!= agent.indexof ("360SE")) {//360 Secure browser String len
filename = urlencoder.encode (filename, "UTF-8"); if (Lenfilename.length () > 150) {//filename length is greater than 150 characters filename = new String (filename.getbytes ("gb2312"), "Iso8859-1"
);
else {filename = urlencoder.encode (filename, "UTF-8"). Replace ("+", "%20"); }}else if (null!= agent &&-1!= agent.indexof ("Chrome") {//google fileName = new String (filename.getbyte S ("gb2312"), "iso8859-1"); The file name of the resolution download contains the parentheses conversion%28%29}else if (null!= agent &&-1!= agent.indexof ("Firefox")) {//firefox filename =
New String (Filename.getbytes ("gb2312"), "iso8859-1"); }else if (null!= agent && 1!= agent.indexof ("Safari")) {//firefox fileName = new String (Filename.getbytes ("U TF-8 "), "iso8859-1");
}else {//other browser fileName = new String (filename.getbytes ("gb2312"), "iso8859-1");
The catch (Exception e) {throw new RuntimeException ("Transfilename error", E);
return fileName;
}
}