JSP page Jump methods and jsp jump Methods
The following describes how to jump to a page in a JSP script on the server:
1. response. sendredirdbms ("Jump to page ");
This method modifies the http header to issue a redirection command to the browser so that the browser displays the content of the redirected webpage. The request cannot pass the value.
After executing all the code on the page, jump to the page. Jump to the address bar and change.
You can jump to the page response. sendredirdbms ('HTTP: // www.bkjia.com ') on another server ').
2. response. setHeader ();
This method is the same as response. sendRedirect by modifying the http header.
<% response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); String newLocn="/index.html"; response.setHeader("Location",newLocn); %>
3. <jsp: forward page = "Jump page"/>
This method uses the server to first output data to the buffer. Before the buffer content is sent to the client, the original content on the page will not be sent, if there are a lot of output before <jsp: forward>, and the previous output will automatically output to the client when the buffer is full, this statement will not work. Pay special attention to this.
Request can pass the value in the past. directly jump to the page, the code behind is not executed. After the jump, the address bar remains unchanged. The page cannot jump to other servers. The picture is not an absolute path and cannot be displayed.
4. request. getRequestDispatcher ("Jump to page ");
Request can pass the value in the past. Execute all the code on the page, and then jump to the page.
The jump Address Bar remains unchanged. You cannot jump to pages on other servers.
<% RequestDispatcher rd = request.getRequestDispatcher("jb51.jsp"); rd.forward(request,response); %>
There are three methods to achieve output redirection:
RESPONSE. SETREDERECT ("URL ")
This method modifies the http header to issue redirection instructions to the browser so that the browser displays the content of the redirected webpage.
Response. sendRedirect ("http://www.bkjia.com/index.html ");
2. The following method can also change the http header attribute. Its principle is the same as that of 1.
<%response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); String newLocn="/index.html"; response.setHeader("Location",newLocn); % >
3. Use <JSP: FORWORD>
This method uses the server to first output data to the buffer. Before the buffer content is sent to the client, the original content on the page will not be sent, if there are a lot of output before <JSP: FORWORD>, and the previous output will automatically output to the client when the buffer is full, this statement will not work. Pay special attention to this.
The above is a jump using JSP scripts on the server side. Let's take a look at how to use front-end HTML and JS for page Jump.
Automatic jump in HTML
<Html>
JavaScript jump
Method 1:
<script languate="javascript"> window.location.replace("http://www.bkjia.com");</script>
Method 2:
<script languate="javascript"> window.location="http://www.bkjia.com";</script>
Method 3:
<script languate="javascript"> document.location.href("http://www.bkjia.com");</script>
Method 4:
The back () and go () Methods of the history object. The go () method requires an integer entry parameter.
<A href = "javascript: history. go (-1)" rel = "external nofollow"> return to the previous step </a>
Or
<A href = "javascript: history. back ()" rel = "external nofollow"> return to the previous step </a>
Both return to the previous page.
Method 5:
Document. formName. action = "test. jsp"; document. formName. submit (); // submit using JS
This method is not recommended
Method 6:
<script language="javascript"> window.navigate("top.jsp");</script>
In fact, there are still many ways to use JS to jump to the page. In this case, only the following methods are listed. Other methods can be used to give full play to your imagination when you have a basic understanding of JS.