JSP implements the method of downloading files from different servers. jsp downloads files
This example describes how to download files from different servers using JSP. We will share this with you for your reference. The details are as follows:
Recently encountered a template download problem in the project: when the server is Tomcat, the file can be downloaded normally, but the template downloaded when it is put online (WebLogic Server) is blank, record the solution.
Public void importSuccess () throws Exception {try {HttpServletResponse response = Struts2Utils. getResponse (); // reset the response. reset (); // set the response header to the binary stream response. setContentType ("application/x-msdownload; charset = UTF-8"); response. setContentType ("APPLICATION/OCTET-STREAM"); response. setContentType ("application/vnd. ms-excel "); response. setHeader ("Content-Disposition", "attachment; filename=complaintsimpmodel.xls"); String path = this. getClass (). getClassLoader (). getResource ("/") // This is the key to the problem. The WebLogic Server must add a "/" in the read "/". getPath (); path = path. substring (1, path. length (); String name = File. separator + path + "complaintsimpmodelmodel.xls "; logger.info ("********************************" + name + "*******************************"); inputStream is = new FileInputStream (name); HSSFWorkbook wb = new HSSFWorkbook (is); // get the file stream OutputStream out = response. getOutputStream (); wb. write (out); is. close (); out. flush (); out. close ();} catch (Exception e) {logger. error ("failed to download and export template", e );}}
Future backup
I hope this article will help you with jsp program design.