Two Methods of page Jump in JSP

Source: Internet
Author: User

1. Forward request jump

Request. getrequestdispather (""). forword (request, response );

Features:

(1) the address bar remains unchanged. Cause: Because the address bar remains unchanged after the jump, the address before the jump is refreshed, or the page before the jump is refreshed, the form will be submitted repeatedly when the form is submitted, A big problem may occur.

(2) values can be transferred across pages. For example, request. setattribute ("MSG", "incorrect user name or password") in. jsp before the jump ");

Request. getattribute ("MSG") in. jsp after the jump ");

In this way, the MSG "incorrect user name or password" before the jump can be passed to the page after the jump.

Note:

(1) The attribute names before and after the transfer must be the same. Otherwise, an nullpointerexception exception occurs because the corresponding value is not obtained.

(2) You must setattribute before getattribute. Otherwise, an nullpointerexception exception occurs.


2. Redirect jump

Response. sendredirect ("");

Features:

(1) Changing the address bar will not cause repeated submission of forms

(2) values cannot be transferred across pages. If you want to pass the value, you can use URL rewriting.

For example, before the jump: Response. sendredirect ("index. jsp? Code = "1001 ");

After jump: String code = request. getparameter ("Code ");

Note: The passed values must have the same name. For example, the names in this example are all codes.



Each of the two methods has its own advantages and disadvantages.

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.