java解决导出Excel时文件名乱码的方法示例:(推荐:java视频教程)String agent = request.getHeader("USER-AGENT").toLowerCase();
response.setContentType("application/vnd.ms-excel");
String fileName = "文件名";
String codedFileName = java.net.URLEncoder.encode(fileName, "UTF-8");
if (agent.contains("firefox")) {
response.setCharacterEncoding("utf-8");
response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes(), "ISO8859-1") + ".xls" );
} else {
response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
}
encode() 方法以指定的编码格式编码字符串。
更多java知识请关注java基础教程栏目。