The comparison of JSP three kinds of page jump way

Source: Internet
Author: User
Tags comparison execution flush

There are approximately three ways to jump using JSPs:

1. response.sendRedirect();
2. response.setHeader("Location","");
3.

Some of the following rules have been tested:

I. Response.sendredirect ()

Out.flush () is not allowed before this statement, and if so, there will be an exception:

java.lang.IllegalStateException: Cant 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 a different host, after the jump, the statement after this statement will continue to execute, as a new thread, but the operation of the response has no meaning;

If you want to jump to the same host, the statement after this statement completes execution before jumping;

Two. Response.setheader ("Location", "")

Out.flush () is not allowed before this statement, and if so, the page will not jump.

Browser address bar changes after jump

The statement after this statement finishes execution does not jump

Three.

Out.flush () is not allowed before this statement, and if so, there will be an exception:

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 does not change after the jump, but only jumps to the current host

The statement after this statement finishes execution does not 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.