Download data to the CSV file from the data

zhaozj2021-02-16  83

Import java.sql. *; import java.io. *; import java.util. *; import javax.servlet. *; import javax.servlet.http. *;

public class DownLoad extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost (request, response);} public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {System.out.println ( "====== DownLoad begin ====="); try {String fileName = "dddd.csv"; OutputStream outs = response.getOutputStream (); DataOutputStream dateOut = new DataOutputStream (outs); // set the output Format response.reset (); response.setContentType ("bin"); response.addhead ("Content-Disposition", "Attachment; FileName = /" " FileName " / ""); for (int i = 0 i <10; i ) {dateout.writebytes (i "/ r / n");} Dateout.close (); outs.close ();} catch (Exce) ption ex) {ex.printStackTrace ();} System.out.println ( "====== DownLoad end =====");}}

转载请注明原文地址:https://www.9cbs.com/read-14535.html

New Post(0)