Comparison of JSP page Jump Methods

Source: Internet
Author: User

There are about three redirect Methods Using JSP:
1. response. sendRedirect ();
2. response. setHeader ("Location ","");
3. <jsp: forward page = ""/>

The following rules are obtained after testing:

I. response. sendRedirect ()

Out. flush () is not allowed before this statement. If yes, an exception occurs:
Java. lang. IllegalStateException: Can't sendRedirect () after data has committed to the client.
At com. caucho. server. connection. AbstractHttpResponse. sendRedirect (AbstractHttpResponse. java: 558)
...
Browser address bar changes after jump
If you want to jump to different hosts, after the jump, the statement after this statement will continue to be executed, as if a new thread, but the response operation has no significance;
If you want to jump to the same host, the statement after this statement is executed will not jump;
2. response. setHeader ("Location ","")

No out. flush () is allowed before this statement. If yes, the page will not jump.
Browser address bar changes after jump
Only after the statement is executed
Iii. <jsp: forward page = ""/>

Out. flush () is not allowed before this statement. If yes, an exception occurs:
Java. Lang. illegalstateexception: Forward () not allowed after buffer has committed.
At com. Caucho. server. webapp. requestdispatcherimpl. Forward (requestdispatcherimpl. Java: 134)
At com. Caucho. server. webapp. requestdispatcherimpl. Forward (requestdispatcherimpl. Java: 101)
At com. Caucho. jsp. pagecontextimpl. Forward (pagecontextimpl. Java: 836)
...
The browser address bar remains unchanged after the jump, but the address bar can only jump to the current host
Only after the statement is executed

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.