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
- The first type is: <JSP: Forward page = ""/>;
-
- The second type is: Response. sendredirect ("Address ");
-
- Third: Response. setheader ("Refresh" , "2; url = responsedemo02.jsp" );
-
- // Automatically jump to the responsedemo02.jsp page in 2 seconds, which is also a redirection Method
Java code
- The first type is: <JSP: Forward page = ""/>;
- The second type is: Response. sendredirect ("Address ");
- Third: Response. setheader ("Refresh","2; url = responsedemo02.jsp");
- // 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.