这里有新鲜出炉的 JSP 学习教程,程序狗速度看过来!
JSP 全名为 Java Server Pages - java 服务器页面是由 Sun Microsystems 公司倡导、许多公司参与一起建立的一种动态网页技术标准。JSP 技术有点类似 ASP 技术,它是在传统的网页 html(标准通用标记语言的子集)文件 (*.htm,*.html) 中插入 Java 程序段 (Scriptlet) 和 JSP 标记(tag),从而形成 JSP 文件,后缀名为(*.jsp)。
下面小编就为大家带来一篇 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 表格的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持 phperz。
来源: http://www.phperz.com/article/17/0813/338926.html