本文实例讲述了JSP实现从数据库导出数据到Excel下载的方法。分享给大家供大家参考,具体如下:
关键代码:
<%@ page contentType="application/msexcel" %> <% //response.setHeader("Content-disposition","inline; filename=videos.xls"); response.setHeader("Content-disposition","attachment; filename=test.xls"); //以上这行设定传送到前端浏览器时的档名为test.xls //就是靠这一行,让前端浏览器以为接收到一个excel档 %>
简单测试例子:
<%@ page language="java" import="java.util.*,java.io.*" pageEncoding="GBK"%> <%@ page contentType="application/msexcel" %> <% //response.setHeader("Content-disposition","inline; filename=videos.xls"); response.setHeader("Content-disposition","attachment; filename=test.xls"); //以上这行设定传送到前端浏览器时的档名为test.xls //就是靠这一行,让前端浏览器以为接收到一个excel档 %> <%@ page import="org.springframework.web.context.WebApplicationContext"%> <%@ page import="com.test.*"%> <%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <% WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); UserManager um = (UserManager) ctx.getBean("userManager"); %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>spring jdbc test</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <br> <table border="1" width="100%"> <tr> <td>id</td> <td>name</td> </tr> <% List<User> users2=um.getUserList(); for(int i=0;i<users2.size();i++) { int t_id2=users2.get(i).getId(); String t_name2=users2.get(i).getName(); %> <tr> <td><%=t_id2 %></td> <td><%=t_name2 %></td> </tr> <% } %> </table> </body> </html>
希望本文所述对大家JSP程序设计有所帮助。
linux学习 HKD 开始20210306 文章目录 linux学习 前言随笔 实操—实用指令 指定...
文章目录 海萤物联网介绍 介绍 特点 节点地址 DCOM 一行代码即可开放能力 一行代...
背景 因为工作岗位的原因,负责制定了关于后端组数据库的规约规范,作为所有产品...
replace方法是javascript涉及到正则表达式中较为复杂的一个方法,严格上说应该是...
PHP如何获取当前页完整URL及其参数 ? echo'http://'.$_SERVER['SERVER_NAME'].':...
nbsp;nbsp;在ie、firefox、chrome浏览器上显示的效果不太一样,主要是前面的空格...
搭建lvs keepalivd DR模式双机热备基础与高可用群集 这里只说keepalivd 软件的原...
Java HashMap removeNode 方法 分析 源码分析仓库 https://github.com/HANXU2018...
这篇文章是展示通过 PHP 语言实现一种带 尾指针 的链表,然后通过链表来实现队列...
本文实例为大家分享了JavaScript实现轮播图的具体代码,供大家参考,具体内容如...