解决java下载文件中文文件名乱码问题(ie,谷歌,火狐)

解决java下载文件中文文件名乱码问题(ie,谷歌,火狐)

    response.setCharacterEncoding("utf-8");  
    response.setContentType("application/msword");  
    String  fileName="哈哈哈哈.doc";  

    if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0) {    
      fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); // firefox浏览器    
    } else if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0) {    
     fileName = URLEncoder.encode(fileName, "UTF-8");// IE浏览器    
    }else if (request.getHeader("User-Agent").toUpperCase().indexOf("CHROME") > 0) {    
     fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");// 谷歌    
  }  
   response.setHeader("Content-Disposition", "attachment; filename=" + fileName);   

你可能感兴趣的:(JavaWeb)