不同浏览器下文件下载,文件名编码问题

 

/**
	 * deal with the fileName encode in the different browsers
	 * @param request
	 * @param fileName
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	private String encodeFileName(HttpServletRequest request, String fileName)
			throws UnsupportedEncodingException {
		String agent = request.getHeader("USER-AGENT");
		if (null != agent && -1 != agent.indexOf("MSIE")) {
			return URLEncoder.encode(fileName, "UTF8").replace("+","%20");
		} else if (null != agent && -1 != agent.indexOf("Mozilla")) {
			return "=?UTF-8?B?"
					+ (new String(Base64.encodeBase64(fileName
							.getBytes("UTF-8")))) + "?=";
		} else {
			return fileName;
		}
	}

 

 
 

 

 

你可能感兴趣的:(文件下载)