public static String getDownloadFileName(HttpServletRequest request, String fileName) { String agent = request.getHeader("User-Agent").toUpperCase(); try { if (agent.indexOf("MSIE") > 0 || agent.indexOf("TRIDENT") > 0 || agent.indexOf("EDGE") > 0) { fileName = URLEncoder.encode(fileName, "UTF-8"); fileName = fileName.replaceAll("\\+", "%20"); } else { fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return fileName; }
时间: 2024-11-02 00:28:40