我已经编写了 Java 代码来将 excel 发送到客户端。当用户单击页面中的按钮时,我正在从 java 脚本调用 servlet。但是文件正在同一个浏览器中打开。相反,如何在没有保存/关闭对话框的情况下不在浏览器内以 excel 格式打开文件?
Java Script 单击一个按钮时
window.location = url+'?Data='+Math.random();
爪哇
String ramdonNumber =this.getHttpRequest().getParameter("Data");
System.out.println("Inside Action"+ramdonNumber);
File file = new File("C:/Documents and Settings/XXXXXX/Desktop/RevisedAvailableSeatForSRESR.xls");
try {
this.setFileInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpServletResponse response = this.getHttpResponse();
response.setHeader("Content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"inline;filename=\"" + file.getName() + ".xls\";");