JSP實(shí)現(xiàn)從數(shù)據(jù)庫導(dǎo)出數(shù)據(jù)到Excel下載的方法
本文實(shí)例講述了JSP實(shí)現(xiàn)從數(shù)據(jù)庫導(dǎo)出數(shù)據(jù)到Excel下載的方法。分享給大家供大家參考,具體如下:
關(guān)鍵代碼:
<%@ page contentType="application/msexcel" %> <% //response.setHeader("Content-disposition","inline; filename=videos.xls"); response.setHeader("Content-disposition","attachment; filename=test.xls"); //以上這行設(shè)定傳送到前端瀏覽器時(shí)的檔名為test.xls //就是靠這一行,讓前端瀏覽器以為接收到一個(gè)excel檔 %>
簡單測試?yán)樱?/p>
<%@ 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"); //以上這行設(shè)定傳送到前端瀏覽器時(shí)的檔名為test.xls //就是靠這一行,讓前端瀏覽器以為接收到一個(gè)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程序設(shè)計(jì)有所幫助。
- JS實(shí)現(xiàn)將數(shù)據(jù)導(dǎo)出到Excel的方法詳解
- js實(shí)現(xiàn)數(shù)據(jù)導(dǎo)出為EXCEL(支持大量數(shù)據(jù)導(dǎo)出)
- Vue導(dǎo)出json數(shù)據(jù)到Excel電子表格的示例
- AngularJs導(dǎo)出數(shù)據(jù)到Excel的示例代碼
- js導(dǎo)出table數(shù)據(jù)到excel即導(dǎo)出為EXCEL文檔的方法
- 通過Javascript將數(shù)據(jù)導(dǎo)出到外部Excel文檔的函數(shù)代碼
- javascript 導(dǎo)出數(shù)據(jù)到Excel(處理table中的元素)
- javascript?實(shí)現(xiàn)純前端將數(shù)據(jù)導(dǎo)出excel兩種方式
相關(guān)文章
淺談SpringMVC jsp前臺獲取參數(shù)的方式 EL表達(dá)式
下面小編就為大家分享一篇淺談SpringMVC jsp前臺獲取參數(shù)的方式 EL表達(dá)式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03JavaScript實(shí)現(xiàn)城市選擇控件的效果
本文介紹了JavaScript實(shí)現(xiàn)城市選擇控件的效果,支持直接輸入城市名稱,拼音首字母,全拼,有需要的朋友可以了解一下。2016-10-10request.getParameter()取值為null的解決方法
在后臺通過Request取值為null,是因?yàn)橹辉O(shè)置了id屬性,而取值候用的是name屬性,問題就出現(xiàn)在這里2014-06-06使用JSP實(shí)現(xiàn)簡單的用戶登錄注冊頁面示例代碼解析
這篇文章主要介紹了使用JSP實(shí)現(xiàn)簡單的用戶登錄注冊頁面示例代碼解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08JAVA/JSP學(xué)習(xí)系列之二(Tomcat安裝)
JAVA/JSP學(xué)習(xí)系列之二(Tomcat安裝)...2006-10-10