JSP实现从数据库导出数据到Excel下载的方法
网络编程 2021-07-05 11:23www.168986.cn编程入门
这篇文章主要介绍了JSP实现从数据库导出数据到Excel下载的方法,涉及JSP操作excel文件导出的相关技巧,非常简单实用,需要的朋友可以参考下
本文实例讲述了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=".springframework.web.context.WebApplicationContext"%> <%@ page import=".test.*"%> <%@ page import=".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程序设计有所帮助。
上一篇:JSP针对表单重复提交的处理方法
下一篇:jsp倒计时简单实现方法
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程