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");
</script>
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
Response
- Execute all the code in the jump to the target page
- The URL of the browser changes after jumping to the target page
- redirect in browser
- Can jump to other pages of the server
Forward
- 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>
<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