想实现的功能是:导出excel,从数据库中查询数据,然后通过poi导出,在浏览器中弹出下载画面,让用户下载
出现的问题有两个:
1.说什么也不弹出下载对话框
2.导出以后中文乱码
问题1解决方法:不能使用ajax,用window.location.href方式调用,解决下载框不弹出的问题
问题2解决方法:参考http://blog.csdn.net/silentmuh/article/details/44417681
需要根据程序运行时系统的编码来生成文件,获得系统编码的方法如下:
public static String getSystemFileCharset(){
Properties pro = System.getProperties();
return pro.getProperty("file.encoding");
}
并设置 response.setCharacterEncoding(getSystemFileCharset()),解决问题2