class="java" name="code">private String getContentDisposition(String filename, String ext, HttpServletRequest req, HttpServletResponse res) throws IOException { StringBuffer tmp = new StringBuffer(); tmp.append("attachment" ); String agent = (String)req.getHeader("USER-AGENT"); tmp.append("; filename="); if(agent != null && agent.indexOf("Firefox") != -1 ){ //Firefox tmp.append("=?UTF-8?B?" + (new String (Base64.getEncoder().encode(filename.getBytes("UTF-8")))) + "?="); tmp.append("."); tmp.append(ext); }else if(agent != null && agent.indexOf("Chrome") != -1 ){ //Chrome tmp.append("\""+new String(filename.getBytes("gb2312"),"ISO8859_1")+"" ); tmp.append("."); tmp.append(ext+"\""); }else if( agent != null && agent.indexOf("Safari") != -1 ){ //Safari tmp.append("\""+new String(filename.getBytes("UTF-8"),"ISO8859_1")+"" ); tmp.append("."); tmp.append(ext+"\""); }else{ //IE tmp.append(new String(filename.getBytes("gb2312"),"ISO8859_1") ); tmp.append("."); tmp.append(ext); } return tmp.toString(); }