說到導出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表格的實例,相信大家都知道了吧!如果你已經學會這些知識了,那么就趕緊操作試試吧!
新聞熱點
疑難解答