用js可以直接在jsp页面导出数据到excel文件,方法很简洁,如下:
第一,
准备一个jsp(暂时取名为export.jsp),内容为:
<%
String context = request.getParameter("sContent");
response.setHeader("Content-type","application/vnd.ms-xls");
response.setHeader("Content-Disposition","attachment;filename=export.xls");
response.setHeader("Expires","0");
response.setHeader("Cache-Control","no-cache,must-revalidate");
response.setHeader("Pragma","no-cache");
out.print(context);
%>
第二,
写一个导出数据的jsp页面(暂时命名为test.jsp),内容如下:
<%
String path = request.getContextPath();
%>