web download files and jump

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

If you do not download files directly through JSP and servlet, you can use the web.xml file to identify the file type to download. If you want to download through servlet, you can download it as follows:

image

image

But there are two disadvantages to downloading in this way: one is that we do not know the size of the file and the download progress, and the other is that we cannot see the file name of the downloaded file, so we did the following:

image

image

This way we can get file size download progress and file name.

When developing web applications, you will encounter the problem of jumping from one page to another. There are two jumping methods in Servlet: Jump
redirection: jump with the browser (this method cannot be used twice), the response is given to If the browser takes a jump, the browser will jump.
Forwarding: The server internally jumps the request to jump, forwards it through the getRequestDispatcher() method, and then forwards it through the forword() method. If you jump, the address displayed in the browser will not change.

image

Experimental test redirection and forwarding:

redirect test

image

image

image

image

Forward test:

image

image

The difference between redirection and forwarding
1. The number of requests is different. The redirection requests the server twice in total; forwarding means that a user request may be returned to the user's browser through N servlet pages, and it is processed multiple times at one time. Process;

2. The link changes during the jump process. The redirection requests the server twice in the jump and it is two different link addresses. You can see that there are two changes in the address bar of the browser; forwarding is jumping. During the process, the browser requests the server once, and the server passes through n servlet pages and does not change the requested link address. Because the user only requests once, the link address does not change during the entire jump process. bar you can see

3. The purpose is different, redirection is simply to let the user access a new link, while forwarding is for the server to get the user's request content and need to perform part of the processing, so the purpose of the two is different.

Attribute("name","aaa"); register aaa in name

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326573891&siteId=291194637
Recommended