java 后臺(tái)返回一個(gè)ModelAndView 對(duì)象,然后加入這2行設(shè)置
response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition","attachment;filename=" + URLEncoder.encode("會(huì)員列表.xls", "UTF-8"));
也可以把這二行設(shè)置放入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("會(huì)員列表.xls", "UTF-8")); %> !DOCTYPE html> html> head> title>CMS-會(huì)員管理/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%">序號(hào)/th> th nowrap width="5%">卡號(hào)/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 導(dǎo)出Excel表格的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
標(biāo)簽:黃石 銅川 南京 貸款邀約 廣州 大連 樂山 內(nèi)江
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《JSP 導(dǎo)出Excel表格的實(shí)例》,本文關(guān)鍵詞 JSP,導(dǎo)出,Excel,表格,的,實(shí)例,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。