Detailed explanation of jsp sendRedirect () method redirection

Source: Internet
Author: User
Tags tomcat server

Directly export to the hello.html page response_demo03.jsp

 

The code is as follows: Copy code

<% @ Page language = "java" contentType = "text/html" pageEncoding = "GBK" %>

<Html>

<Head>

<Title> Test </title>

</Head>

<Body>

<%

Response. sendRedirect ("hello.html ");

%>

</Body>

</Html>

This jump is a client jump.

<Jsp: forward> is a server jump. The address does not change. You can save the request attribute to the jump page.
Response. sendRedirect () is a client jump, and the address will change. You cannot save the request attribute to the jump page.
Another difference is that the server jump will jump immediately, and the client jump will only jump after the entire page is executed.

Server jump response_demo04.jsp

The code is as follows: Copy code

<% @ Page language = "java" contentType = "text/html" pageEncoding = "GBK" %>

<Html>

<Head>

<Title> Test </title>

</Head>

<Body>

<%

System. out. println ("---------- forward jump to the previous -------------");

%>

<Jsp: forward page = "hello.html"/>

<%

System. out. println -------------");

%>

</Body>

</Html>


 

Display result: hello
However, the background of the tomcat server displays ---------- ----------- before the forward jump -------------

The code is as follows: Copy code

Client jump response_demo05.jsp

View sourceprint? <% @ Page language = "java" contentType = "text/html" pageEncoding = "GBK" %>

<Html>

<Head>

<Title> Test </title>

</Head>

<Body>

<%

System. out. println ("---------- before the response jump -------------");

%>

<%

Response. sendRedirect ("hello.html ");

%>

<%

System. out. println ------------");

%>

</Body>

</Html>

The tomcat server background displays ---------- ----------- before the response jump -------------
-------------

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.