JSP 导出Excel表格的实例

下面小编就为大家带来一篇JSP 导出Excel表格的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

java 后台返回一个ModelAndView 对象,然后加入这2行设置

response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition","attachment;filename=" + URLEncoder.encode("会员列表.xls", "UTF-8"));

也可以把这二行设置放入JSP中

jsp代码如下:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition","attachment;filename=" + java.net.URLEncoder.encode("会员列表.xls", "UTF-8")); %> <!DOCTYPE html> <html> <head> <title>CMS-会员管理</title> <meta charset="utf-8" /> <meta http-equiv="pragma" content="no-cache"/> <meta http-equiv="cache-control" content="no-cache"/> <meta http-equiv="expires" content="0"/> </head> <body> <table cellpadding="2" cellspacing="1"> <thead> <tr> <th nowrap>序号</th> <th nowrap>卡号</th> <th nowrap>姓名</th> <th nowrap>年龄</th> </tr> </thead> <tbody> <c:forEach items="${list}" var="model" varStatus="status" > <tr> <td>${model.id}</td> <td>${model.cardNo}</td> <td>${model.name}</td> <td>${model.age}</td> </tr> </c:forEach> </tbody> </table> </body> </html>

以上这篇JSP 导出Excel表格的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjdxs.html