麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

SpringMVC的Excel導出(彈框提示下載)

2019-11-10 19:17:21
字體:
來源:轉載
供稿:網友

重要的事情說三遍!!!!

jQuery的Ajax函數、及ajaxSubmit等函數的返回類型(dataType)只有xml、text、json、html等類型,沒有“流”類型.

jQuery的ajax函數、及ajaxSubmit等函數的返回類型(dataType)只有xml、text、json、html等類型,沒有“流”類型.

jQuery的ajax函數、及ajaxSubmit等函數的返回類型(dataType)只有xml、text、json、html等類型,沒有“流”類型.

所以想要彈框下載,就不能用Ajax來做!!!!

jsp

<span class="btn" onclick="Excel_export()">EXCEL導出</span> <div style="display: none;"> <form action= "login/excel_download.action" method="get"> <input type="text" id="startime" name="startime"> <input type="text" id="stoptime" name="stoptime"> <input type="text" id="mintemp" name="mintemp"> <input type="text" id="maxtemp" name="maxtemp"> <input type="text" id="winds" name="winds"> <input type="text" id="id" name="id"> <input type="submit" id="sub" value="Submit" />         </form></div>

JS

function excel_export(){ $("#startime").val(begaintime); $("#stoptime").val(endtime); $("#mintemp").val(wind_sp); $("#maxtemp").val(min_temp); $("#winds").val(max_temp); $("#id").val(a1); $("#sub").click();}

后臺:

@RequestMapping(value = "excel_download") @ResponseBody public void  excel_download(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setCharacterEncoding("utf-8"); resp.setHeader("Cache-Control", "no-cache"); String fileName = "excel文件"; String startime = req.getParameter("startime"); String stoptime = req.getParameter("stoptime"); String mintemp = req.getParameter("mintemp"); String maxtemp = req.getParameter("maxtemp"); String winds = req.getParameter("winds"); String id = req.getParameter("id"); System.out.PRintln(startime+","+stoptime+","+mintemp+","+maxtemp+"<"+winds+","+id); Map<String, Object> param=new HashMap<String, Object>();  param.put("id", id.substring(1, id.length())); param.put("startime", startime); param.put("stoptime", stoptime); param.put("mintemp", mintemp); param.put("maxtemp", maxtemp); param.put("winds", winds); List<RecordInfo> r = recordService.GetRecordByCondition_excel(param); System.out.println(r); // PoiExpExcel.main(r); String[] title = {"序號","風速","記錄時間","溫度"}; HSSFWorkbook workbook = new HSSFWorkbook(); //創建一個工作表sheet HSSFSheet sheet = workbook.createSheet(); //創建第一行 HSSFRow row = sheet.createRow(0); HSSFCell cell = null; //插入第一行數據title for(int i= 0; i < title.length; i++){ cell = row.createCell(i); cell.setCellValue(title[i]); } //追加數據 for(int i= 1; i <= r.size(); i++){ HSSFRow nextrow = sheet.createRow(i); HSSFCell cell2 = nextrow.createCell(0); cell2.setCellValue(i); cell2 = nextrow.createCell(1); cell2.setCellValue(r.get(i-1).getRecord_wind_speed()); cell2 = nextrow.createCell(2); cell2.setCellValue(r.get(i-1).getRecord_time()); cell2 = nextrow.createCell(3); cell2.setCellValue(r.get(i-1).getRecord_temp()); } //創建一個文件 /*File file = new File("C:/Users/Administrator/Desktop/poi_test.xls"); try { file.createNewFile(); //將EXCEL內容存盤 FileOutputStream stream = FileUtils.openOutputStream(file); workbook.write(stream); stream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ ByteArrayOutputStream os = new ByteArrayOutputStream();        try {         workbook.write(os);        } catch (IOException e) {            e.printStackTrace();        }        byte[] content = os.toByteArray();        InputStream is = new ByteArrayInputStream(content);        // 設置response參數,可以打開下載頁面        resp.reset();        resp.setContentType("application/vnd.ms-excel;charset=utf-8");        resp.setHeader("Content-Disposition", "attachment; filename=" + new String((fileName + ".xls").getBytes(), "iso-8859-1"));        ServletOutputStream out = resp.getOutputStream();        BufferedInputStream bis = null;        BufferedOutputStream bos = null;        try {            bis = new BufferedInputStream(is);            bos = new BufferedOutputStream(out);            byte[] buff = new byte[2048];            int bytesRead;            // Simple read/write loop.            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {                bos.write(buff, 0, bytesRead);            }        } catch (final IOException e) {            throw e;        } finally {            if (bis != null)                bis.close();            if (bos != null)                bos.close();        } }
上一篇:HashMap原理詳講

下一篇:Golang API 類型 Get

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 超碰97人人艹 | 经典三级在线视频 | 午夜小视频免费观看 | 欧美成人亚洲 | 久久久久北条麻妃免费看 | 青青草免费观看 | 国产成人观看 | 萌白酱福利视频在线网站 | 国产精品片一区二区三区 | 国产小视频在线 | 久色乳综合思思在线视频 | 欧美一级成人一区二区三区 | 成人一区久久 | 欧美a级一区二区 | 香蕉国产精品 | 欧美亚洲国产一区二区三区 | 亚洲第一成人av | 中文字幕涩涩久久乱小说 | 精品中文字幕久久久久四十五十骆 | 91精品国产刺激国语对白 | 高清av免费 | 欧美精品久久天天躁 | 视频一区二区三区在线播放 | 一级国产航空美女毛片内谢 | 亚洲射吧 | 在线观看麻豆 | 欧美一级在线免费 | 播色网| 成人在线观看免费观看 | 欧美成人一二三区 | 午夜生活理论片 | 久久久久久久一区 | 亚洲一区二区三区精品在线观看 | 日本一道aⅴ不卡免费播放 久久久久久久高清 | 久久国产秒| www.99久 | 久久99亚洲精品 | 免费一级欧美 | 国产精品视频自拍 | 一级裸体视频 | 欧洲成人一区二区 |