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.