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 =====");}}