1. Two ways to implement file downloads in Web applications
Hyperlinks point directly to the download resource, the program implementation download needs to set two response headers:
Set the Content-type value to: Application/x-msdownload. The WEB server needs to tell the browser that the type of content it outputs is not a normal text file or an HTML file, but rather a download file to be saved locally.
The WEB server wants the browser to not work directly with the corresponding entity content, but rather the user chooses to save the corresponding entity content to a file, which requires setting the Content-disposition header. The header specifies how the receiving program handles the content of the data, and only attachment is the standard way in HTTP applications, attachment indicates that user intervention is required . You can also specify the filename parameter after attachment , which is the name of the file that the server recommends the browser to save the entity contents to a file. Be sure to specify content-type before setting content-dispostion.
Because the files to be downloaded can be of various types of files, the corresponding content should be treated as binary when the file is routed to the client, so the method should be called to return the Serveltoutputstream object to write the text to the client Piece of content.
2. Download the case
All files in the upload directory are displayed to the user and the user is allowed to complete the download.
(Read all the files under a folder, save them to the list in the collection, and save to the request scope) listfileservelt-(show all the file lists) listfiles.jsp-----Downloaservlet.java
3. To say that a little bit of the theory is not dizzy, then a bit of practical case analysis:
Download the page of the Jump listfile.jsp <%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8" "%> <%@ taglib uri=" htt P://java.sun.com/jsp/jstl/core "prefix=" C "%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >