Two jump methods and differences in JSP

Source: Internet
Author: User

// Note: Chinese file names such as "target page. jsp" are not recommended.

1. Response jump:

// Jump with session and without request (client jump)
Responst. sendredirect ("target page. jsp ");

2. Forward jump:
<JSP: Forward page = "Jump page address"/>
// Jump with session and request (server jump)
// You need to add the parameter request. setattribute ("myvar", "value") to the request ");
// Obtain the parameter on the target page: String myvar = request. getattribute ("myvar") = NULL? "": (String) request. getattribute ("myvar ");
Request. getrequestdispatcher ("target page. jsp"). Forward (request, response );

-


1. Forward jump:
A. The server jumps, and the address bar does not change;
B. The Code will not be executed immediately after the jump statement is executed (all resources must be released before the jump );
C. The property set in the request can still be used on the page after the jump;
D. Use <JSP: Param name = "parameter name" value = "parameter value"/> to pass the parameter.


2. Response jump:
A. The client jumps and the address bar changes;
B. jump after all code execution is complete;
C. The request attribute of the previous page cannot be used for the redirected page;
D. Use the address to override the pass parameter (response. sendredirect ("url? Parameter Name = parameter value ")).


Differences between the two jumps in JSP

There are two types of jumps in JSP: client jump and server jump. There are four differences between them:

1. <JSP: Forward page = ""/> as a server jump, the address bar after the jump is the current address, not the target page. Response. sensrediresct ("") is the address of the target page when the client jumps to the address bar.

2. client jump when the program executes this sentence, it is to execute the jump action after all the code is executed, that is, the subsequent Code has the opportunity to be executed, and the server jump is tough, when this sentence is executed, force redirect without executing the subsequent code.

3. From the perspective of passing parameters, you can pass parameters through address Rewriting for client-end redirects, such as response. sendredirect (*. jsp? Ref = pokoo & ref2 = pokoo2). For server redirection, <JSP: Param name = "Ref" value = "pokoo"/> can be used to pass parameters.

4. JSP has four property storage scopes. For example, if the property is saved in the request in the current resource, the client cannot jump to the target page and the content in the request container is not available, however, the server jump can be obtained.

The following describes the storage range of four attributes in JSP and the nine built-in objects in JSP, The jstl tag library, and the development of simple JSP tags.

The servlet does not contain <JSP: Forward page = ""/>. Therefore, the server jumps to the request using requestdispatcher RD = request. getrequestdispatcher ("*. JSP "); Rd. forward (request, response );

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.