String userAgent = request.getHeader("user-agent").toLowerCase(); if (userAgent.contains("msie") || userAgent.contains("like gecko") ) { // win10 ie edge 浏览器 和其他系统的ie fileName = URLEncoder.encode(fileName,"UTF-8"); fileName = fileName.replaceAll("\\+", "%20").replaceAll( "\\(","%28").replaceAll( "\\)","%29").replaceAll( ";","%3B").replaceAll( "@","%40").replaceAll( "\\#","%23").replaceAll( "\\&","%26").replaceAll( "\\,","%2C"); } else { // fe fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1"); } response.addHeader("Content-Disposition", "attachment;filename="+ fileName);
文件名转换的方法要放对地方,放在返回文件下载信息里。