JSP 导出Excel表格的实例
程序员文章站
2023-11-21 17:08:28
java 后台返回一个modelandview 对象,然后加入这2行设置
response.setcontenttype("application/vnd.ms-...
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表格的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。