Why can the code after response. sendredirect () in JSP still be executed?

Source: Internet
Author: User

Test. jsp page
1. system. Out. println ("before response. sendredirect ");
2. response. sendredirect ("/target. jsp ");
3. system. Out. println ("After response. sendredirect ");
Why is the execution performed in line 3?
I thought that sendredirect was executed, and the request was redirected. The code below should not be executed, but now we want to continue the execution. Please explain it clearly. Thank you.

// ================================================ ========================================================== ==================================

Where is return the end of a method?
As long as return is not added, all the code after sendredirect will be executed? When will the page Jump?
As you said, how can such code go?
Response. sendredirect ("/a. jsp ");
Response. sendredirect ("/B. jsp ");
Response. sendredirect ("/C. jsp ");
Response. sendredirect ("/D. jsp ");

// ================================================ ========================================================== ==================================

I agree that csdn_pistachio and sendredirect () are nothing more than a common method call,
I personally think response. sendredirect ("/a. jsp ");
Response. sendredirect ("/B. jsp ");
Response. sendredirect ("/C. jsp ");
Response. sendredirect ("/d. JSP "); finally to D. JSP only allows the client browser to send three redirection commands. does not affect the server. therefore, you can perform database storage and processing later.

// ================================================ ========================================================== ==================================

Back to WTS (Tiansheng) & xchn (xchn)

Although no output can be made to reponse after sendredirect () is called (including re-sendredirect, so the upstairs statement is also wrong ), however, the browser has not actually received this command. The redirection command is sent to the client only after the code after sendredirect is executed, and then the client browser requests a new URL. This is the execution process of redirection.

// ================================================ ========================================================== ==================================

"I thought sendredirect was executed, and the request was redirected. The code below should not be executed. But now we want to continue executing the code. Please explain it clearly. Thank you ."

Do not use the behavioral characteristics of traditional Java applications to view the behavioral characteristics of Web applications in B/S.

In fact, the verification is very simple. add a loop delay before the out, and check whether the redirection page comes out first or the console's "After response. sendredirect "can be determined now.

Add code:
Response. sendredirect ("date. jsp ");
Response. flushbuffer (); // It can prove that even if it has been submitted, it has not been sent to the client immediately
For (INT I = 0; I <9999; I ++) // The numeric size depends on the performance of your machine.
For (Int J = 0; j <99999; j ++ );
System. Out. println ("after redirect ");

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.