JSP實現將查詢的結果匯出到一個EXCEL檔案中,在頁面上提供下載。點擊下載時卻出現了問題, 每次點擊時彈出的儲存對話方塊的檔案類型卻是htm,卻不是xls,為此自己寫了一個下載程式,不是調用IE的下載程式;代碼如果下<%@page import="java.util.*"%> <%@page import="java.io.*"%> <%@page import="java.net.*"%> <% String filename = ""; if (request.getParameter("file") != null) { filename = request.getParameter("file"); } out.write(filename); //response.setContentType("application/msnotepad"); response.setHeader("Content-disposition","attachment; filename="+filename); BufferedInputStream bis = null; BufferedOutputStream bos = null; try { bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("downloads/" + filename))); bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[2048]; int bytesRead; while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) { bos.write(buff,0,bytesRead); } } catch(final IOException e) { System.out.println ( "³öÏÖIOException." + e ); } finally { if (bis != null) bis.close(); if (bos != null) bos.close(); } //return; %>