SpringMVC excel匯出遇到的問題
阿新 • • 發佈:2019-01-02
問題:點選匯出excel按鈕後無反應
之前我使用的ajax來做的,點選後沒有反應,除錯了半天才發現ajax的方式行不通,不知道大神些是怎麼玩的,反正我改成了form表單提交就可以了
1.form表單
<form id="exportData" action="<%=request.getContextPath() %>/logController/exportLukyBallDate.do" method="post"> <input type="hidden" name="fileName" value="匯出.xls"/> <input type="hidden" value='exportData' name="method" /> </form>
2、js
function exportData(previous_id){
alert("匯出:"+previous_id);
document.getElementById("previous_id").value=previous_id;
document.getElementById("exportData").submit();
}
3、Controller
@RequestMapping(value = "/logController") public class DataHisBallController { //excle匯出 @RequestMapping(value="/exportLukyBallDate") public String exportLukyBallDate(String getPreviousId,HttpServletRequest request,HttpServletResponse response){ String previous_id = request.getParameter("previous_id"); String fileName = request.getParameter("fileName"); response.setContentType("application/ms-excel;charset=UTF-8"); try { response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8")))); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }
4、效果