JSP 导出Excel表格的实例
来源:爱站网时间:2020-02-10编辑:网友分享
说到导出Excel表格,相信大家都会想到办公软件,爱站技术频道小编今天在这里就和大家分享JSP 导出Excel表格的实例,一起进入下文来学习吧!
说到导出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 id="sample-table-1" border="1" cellpadding="2" cellspacing="1"> <thead> <tr> <th nowrap width="15%">序号</th> <th nowrap width="5%">卡号</th> <th nowrap width="5%">姓名</th> <th nowrap width="5%">年龄</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表格的实例,相信大家都知道了吧!如果你已经学会这些知识了,那么就赶紧操作试试吧!
上一篇:SpringMVC程序简单实例