public static void exportFile(List<Object> list) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
StringBuffer sb = new StringBuffer();
sb.append("地 址\t姓名\t性别\t证件号码\t登记日期\t户籍详址\t派出所\r\n");
for (int i = 0; i < list.size(); i++) {
Map<String, String> map = (Map<String, String>) list.get(i);
sb.append(map.get("DZ") +"\t"
+map.get("XM") +"\t"
+map.get("XB") +"\t"
+map.get("ZJHM")+"\t"
+map.get("DJRQ")+"\t"
+map.get("HJXZ")+"\t"
+map.get("PCS") +"\t");
sb.append("\r\n");
}
String[] ss = new String[2];
ss[0] = sb.toString();
String filepath = "exportTxt.txt";
String uuid = UUID.randomUUID().toString().replaceAll("-","");
response.setContentType("application/octet-stream; charset=gbk");
response.setHeader("Content-disposition", "attachment; filename=\"" + uuid + ".txt\"");
PrintWriter pw = null;
try {
pw = response.getWriter();
pw.print(ss[0]);
pw.println("");
} catch (Exception e) {
}finally{
}
}