Three methods for page Jump in JSP and their differences

Source: Internet
Author: User
Three methods for page Jump in JSP and their differences

Redirection can be used to achieve the jump. After the jump, the page address becomes the address after the jump.

We already know there are two jump methods.

Java Code
    1. The first type is: <JSP: Forward page = ""/>;
    2. The second type is: Response. sendredirect ("Address ");
    3. Third: Response. setheader ("Refresh" , "2; url = responsedemo02.jsp" );
    4. // Automatically jump to the responsedemo02.jsp page in 2 seconds, which is also a redirection Method
Java code
    1. The first type is: <JSP: Forward page = ""/>;
    2. The second type is: Response. sendredirect ("Address ");
    3. Third: Response. setheader ("Refresh","2; url = responsedemo02.jsp");
    4. // Automatically jump to the responsedemo02.jsp page in 2 seconds, which is also a redirection Method
 
The first is: <JSP: Forward page = ""/>; the second is: response. sendredirect ("Address"); 3: response. setheader ("refresh", "2; url = responsedemo02.jsp"); // The responsedemo02.jsp page is automatically redirected 2 seconds later. This is also a redirection method.

[Response. setheader ("refresh", "1"); indicates that the page will be automatically refreshed in 1 second]

What are the differences between the two types of redirects? [Frequently encountered during interviews]

<JSP: Forward page = ""/>
-The address remains unchanged after the jump. This type of jump is called server-side jump.

The statement after the jump statement is not executed.

The request attribute can be retained.

PASS Parameters through <JSP: Param name = "" value = ""/>

Response. sendredirect ("Address "):

After the jump, the address changes. This type of jump is called client jump.

The code before and after the jump statement is executed and then jumps.

The request attribute cannot be retained, the address is changed, and the client jumps.

You can rewrite the URL to pass the parameters through client redirection.

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.