1. 程式人生 > >以流的形式將檔案寫入頁面,直接下載

以流的形式將檔案寫入頁面,直接下載

try {

OutputStream out = response.getOutputStream();

response.reset();

response.setHeader("content-disposition",

"attachment;filename="+java.net.URLEncoder.encode(reportName,"UTF-8")+".xls");

response.setContentType("APPLICATION/msexcel");

wb.write(out);

out.close();

} catch (FileNotFoundException e) {

throw new DAOException("");

} catch (IOException e) {

throw new DAOException("");

}