JSP implements the method of exporting data from database to Excel downloading _jsp programming

Source: Internet
Author: User

This article describes the JSP implementation from the database export data to Excel download method. Share to everyone for your reference, specific as follows:

Key code:

<%@ page contenttype= "Application/msexcel"%>
<%//response.setheader
  ("Content-disposition", " Inline Filename=videos.xls ");
  Response.setheader ("Content-disposition", "attachment; Filename=test.xls");
  The above line sets the file name Test.xls//That is to be sent to the front-end browser to
  allow the front-end browser to receive an Excel file 
%>

Simple Test Example:

<%@ 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"); The above line setting is routed to the front-end browser when the filename is Test.xls//is on this line, so that the front-end browser to receive an Excel file%> <%@ page import= "Org.springframework.web.contex T.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";  

I hope this article will help you with JSP program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.