Web file download and redirection methods, web file download jump
If you do not use JSP or servlet to directly download files, you can use the web. xml file to identify the file type for download. If you want to download through servlet, you can download it as follows:
However, the downloading method has two disadvantages: we do not know the file size and download progress, and we cannot see the file name. Therefore, we performed the following operations:
In this way, we can get the file size download progress and file name.
When developing a Web application, you may encounter a jump from one page to another. There are two redirect methods in Servlet:
Jump
Redirection: in combination with browser jump (this method cannot be used twice), if response gives the browser a jump, the browser will jump.
Forward: the server jumps to the request and uses the getRequestDispatcher () method to forward the request. Then, the request goes through the forword () method. The address displayed in the browser remains unchanged when the request is redirected.
Tutorial test redirection and forwarding:
Redirection Test
Forwarding test:
What is the difference between redirection and forwarding?
1. the number of requests varies. Redirection requests are sent to the server twice in total. Forwarding means that a user request may go through N Servlet pages at a time and return to the user's browser, is the process of processing a request multiple times;
2. when the link changes during the jump process, the redirection requests two servers in the jump and uses two different link addresses. the browser's address bar shows two changes; during the redirection process, the browser requests the server once. After the server passes through n Servlet pages, the request URL is not changed because the user requests only once, therefore, the link address remains unchanged throughout the jump process. You can see it in the address bar of the browser.
3. Different purposes. Redirection simply allows users to access a new link, while forwarding requires the server to obtain the user's request content and process part of the content. Therefore, the two have different purposes.