Web file download and redirection methods, web file download jump

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.