导出文件时出现另存为框

// 这个是 Servlet中的一个方法
@RequestMapping("/antiDataExport")
	public String antiDataExport(HttpServletRequest request, HttpServletResponse response) throws Exception{
		// 导出excel设置响应头
		response.setHeader("Content-Disposition",
                "attachment;filename=默认文件名.xls");
        response.setHeader("Connection", "close");
        response.setContentType("application/x-msdownload;charset=utf-8");
        response.flushBuffer();
 
     // 测试学生(构造自己的测试数据)
		ExportExcel<Student> ex = new ExportExcel<Student>();
		String[] headers = { "学号", "姓名", "年龄", "性别", "出生日期" };
		List<Student> dataset = new ArrayList<Student>();
		dataset.add(new Student(10000001, "张三", 20, true, new Date()));
		dataset.add(new Student(20000002, "李四", 24, false, new Date()));
		dataset.add(new Student(30000003, "王五", 22, true, new Date()));
/*		for (int i = 0; i < 50000; i++) {
			dataset.add(new Student(30000003, "王五", 22, true, new Date()));
		}*/

        ServletOutputStream     out     =     response.getOutputStream(); 
        // 写入到excel ,该方法的实现没有给出,自己实现就行了
        ex.exportExcel("a",headers, dataset, out,"yyyy-MM-dd");
        out.close();
        // 页面返回值一定得是null
		return null;
	}


文件导出不能使用Ajax的方法,必须使用跳转的方式,因为要重置客户端

你可能感兴趣的:(导出文件时出现另存为框)