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.