日期:2014-05-19 浏览次数:20731 次
// 导出表数据 public String exportTable() throws IOException { HttpServletResponse response = ServletActionContext.getResponse(); //response.setCharacterEncoding("UTF-8"); // 取得输出流 OutputStream out = response.getOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(out); String tableName = request.getParameter("msg");// 从页面上获取所有的表名和其标题 System.out.println(tableName); String[] tableNames = StringUtils.split(tableName, ","); System.out.println("=======================================" + tableNames.length); for (int i = 0; i < tableNames.length; i++) { System.out.println(tableNames[i]); } //取得exportBackUP方法的返回值 String backUpString = this.sjkbfService.exportBackUp(tableNames); System.out.println("写入的文件:"+backUpString); String fileDate = new SimpleDateFormat("yyyyMMddHHmmss") .format(new Date()); String fileName = fileDate + ".backUp"; response.addHeader("Content-Disposition", "attachment;filename=" + fileName); // filename指定默认的名字 //OutputStream bos = response.getOutputStream(); //OutputStream bos = new BufferedOutputStream(out); try { bos.write(backUpString.getBytes("UTF-8")); System.out.println("写入成功"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } bos.close(); out.close(); response.flushBuffer();// 强行将响应缓存中的内容发送到目的地 return null; }