l--page Jump

Source: Internet
Author: User

Brief introduction
    • Web page jump and common processing methods
JSP Common Jump Way
    • 1.href hyperlink tag (client jump)
<href= "hello.jsp">a tag jump </a> 
    • 2 . Complete with JavaScript (client jump)
1.javascript Submitting a form
<Scripttype= "Text/javascript"> functionSubmit () { with(document.getElementById ("Submit") ) {action= "hello.jsp"; Method= "Post"; Submit (); } }</Script>
2.window.location Direct Positioning
<script type= "Text/javascript" >
Window.self.location = "hello.jsp";
Window.location.replace ("http://www.cnblog.com");
3. Using the History object's Foward (), Back (), Go () method
where the Go () method requires a shaping entry parameter
<a href= "Javascript:history.go (-1);" > Back to previous </a> equivalent to
<a href= "Javascript:history.back (); > Back to previous </a>
    • 3. Submit form complete jump (client jump)
<formname= "Form1"Method= "POST"Action= "hello.jsp">    <inputtype= "text"name= "Name">    <inputtype= "text"name= "Password">    <inputtype= "Submit"value= "Submit"></form> 
    • 4. Using JSP built-in object response (client jump)
1. Directly using Sendredirect () redirection, the URL of the redirected page appears on the browser address bar afterredirection <% response.sendredirect ("http:    // Www.cnblogs.com "); %>
The URL in Ps:sendredirect () can have parameters, such as Sendredirect ("Http://www.cnblogs.com?name=" +name "), which can be passed to the parameter at the time of the jump, in addition, The General Response.sendredirect () immediately follows a return, and since the turn is already being made, the output after the sendredirect has no meaning and may lead to a steering failure.
2. Using the SetHeader () method, directly modify the address bar to achieve page redirection
Response.setheader ("Refresh", "1; url = http://www.cnblogs.com ");
Standard format: Response.setheader ("Refresh", "number of seconds to wait; url = absolute path or relative path ")
    • 5. Using the RequestDispatcher class (server-side jump)
RequestDispatcher rd = request.getrequestdispatcher ("target page"); Rd.forward (response,request);

A servlet can get RequestDispatcher objects in two ways:

ServletContext's Getrequestdispatcher ()

ServletRequest's Getrequestdispatcher ()

Call ServletContext's Getrequestdispatcher (String path) method, which specifies the path to the target component.

The Getrequestdispatcher String path method that calls ServletRequest differs from the previous way in that the path parameter of the former must be an absolute path, while the latter's path parameter can be either an absolute or a relative path. The so-called absolute path refers to the path that begins with the symbol "/" and "/" represents the URL entry for the current web app.   

Response redirect and forward jump differences


    1. Execute all the code in the jump to the target page
    2. The URL of the browser changes after jumping to the target page
    3. redirect in browser
    4. Can jump to other pages of the server


    • Jump directly to the target page, followed by code no longer executed
    • URL does not change after jumping to target page
    • End multiplicity directed at the server
    • Unable to jump to a page on a different server
Block a tag jump
    • 1. Return False in the OnClick property of the a tag or in the onclick time
<href= ""= "do (); return false">dosomething  </a>
This is a question of execution order,<a> the order of execution of this tag is to execute the onclick script first and then execute the href parameter to specify the page's jump. return false in the onclick to terminate the workflow of the <a> tag, i.e., do not let the page jump to the page specified by the href parameter
    • 2. Use href = "javascript:void (0)" This pseudo-protocol
<href= "javascript:void (0)"  onclick= "Do ()"> DoSomething</a>
    • 3.href = "#"
<href= "#"  onclick= "Do ()"> DoSomething</a>
Always jump to the top of the current page, page content, there will be a jump feeling
    • 4.href = "# #" compared to 3, will not go back to the top of the page, a better choice)

l--page Jump

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.