目前还不清楚您在哪里阅读您的数据。您需要创建一个InputStream来读取数据。
然后,您首先需要将响应头设置为
HttpServletResponse.setHeader("Content-Disposition", "attachment; filename=datafile.xls");
使用任何你需要的文件名。
然后设置MIME类型:
response.setContentType("application/vnd.ms-excel");
使用MIME类型,你需要。
这时需要使用响应对象来获取它的OutputStream -
OutputStream outStream = response.getOutputStream();
现在写它:
byte[] buf = new byte[4096];
int len = -1;
//Write the file contents to the servlet response
//Using a buffer of 4kb (configurable). This can be
//optimized based on web server and app server
//properties
while ((len = inStream.read(buf)) != -1) {
outStream.write(buf, 0, len);
}
outStream.flush();
outStream.close();
这个答案给了我一个提示,以解决我的问题..非常感谢 – 2012-08-05 08:51:01