// 导出表数据
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; }
后台也打印了写入成功
System.out.println("写入成功");就是要弹出一个下载框,显示下载路径??没有弹出框???
response.addHeader("Content-Type", "application/octet-stream");2、或者在WEB服务器的配置中添加文件后缀名与MIME类型的映射。如tomcat在\apache-tomcat-6.0.26\conf\web.xml的<mime-mapping>结点中配置。
response.reset();
//response.setContentType("application/x-msdownload");
//response.setHeader("Location", fileName);
response.addHeader("Content-Type", "application/octet-stream");
response.addHeader("Content-Disposition", "attachment;filename="+ fileName);
//response.addHeader("Content-Disposition", "attachment; filename=" + response.encodeURL(fileName));
//response.reset();
// response.setContentType("application/octet-stream");
// response.setHeader("Content-Disposition", "attachment;filename=" + fileName); // filename指定默认的名字
// response.addHeader("content-type","application/x-msdownload");
// response.addHeader("Content-Disposition","attachment;filename="+fileName);
//response.addHeader("Content-Disposition","attachment;filename=文件名.rar");
//OutputStream bos = response.getOutputStream();
//OutputStream bos = new BufferedOutputStream(out);
try {试了好些,就是不弹,是不是那个respone有问题???
使用SmartUpload试下