meta http-equiv = "refresh" and 13 Jump page methods

·

meta http-equiv = "refresh" and 13 Jump page methods

Us say 13 kinds of the page jump method

 

First to introduce the server side JSP script jumps four methods of the page:

First, the server-side JSP script jumps in

1. 

response.sendRedirct ( "Jump to page");
the method by modifying the HTTP protocol HEADER part, the browser redirects issued instructions that redirects the browser to display the contents of a web page request can not pass the value of the past.

After executing all the code page, and then jump to the page. Jump address bar change.
Can jump to the page response.sendRedirct on other servers ( '// www.jb51.net').

 

2.

response.setHeader ();
The method and response.sendRedirect as by modifying part of the HTTP protocol HEADER

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn=”/index.html”;
response.setHeader(“Location”,newLocn);

 

3.

<Jsp: forward page = "jump page" />
The first method is to use the server to the data output buffer mechanism for, before sending the buffer contents to the client, the original does not transmit, to the transmission content of the page, if: there are a lot before output, the previous output has enabled the buffer is full, it will automatically output to the client, then the sentence will not work, it should pay special attention to <jsp forward>.

request can pass the value of the past. jump directly to the page, the back of the code is not executed. After the jump address bar unchanged. can not jump to the page on another server. Image is not an absolute path can not be displayed.

 

4.request.getRequestDispatcher ( "jump page");
Request can pass all the values of the past after executing the page code, and then jump to the page.
Jump can not change the address bar to jump to other pages on the server.

RequestDispatcher rd = request.getRequestDispatcher(“jb51.jsp”);
rd.forward(request,response);

 

Second, do the output redirection: (3 methods)

 

RESPONSE.SETREDERECT ( "URL")

A first method
of the HTTP protocol by modifying the method HEADER section, browser redirect instruction issued the browser to display the contents page redirection.

 

response.sendRedirect(“//www.jb51.net/index.html”);

The second method
following method can also change the HTTP HEADER attribute, its principle and 1 is the same.

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); String
newLocn=”/index.html”; response.setHeader(“Location”,newLocn); % ><
br>

A third method. Using

< JSP:FORWORD>

The first method is to use the server to the data output buffer mechanism for, before sending the buffer contents to the client, the original is not transmitted, instead of transmitting the content of the page, if: there before <JSP FORWORD> many output, the output has been in front of the buffer is full, it will automatically output to the client, then the sentence will not work, it should pay special attention.

The above is in some ways the use of server-side JSP script jump, let's look at how to use front-end HTML, JS do the jump page
HTML language automatically jump

<HTML>  
<head>   
<Meta HTTP-equiv = "Refresh" Content = "0; URL =" // www.jb51.net ">   
0 is the waiting time, if set 5 represents a jump start waiting 5s  
</ head>

 

 

Three, JavaScript jump (6 ways)

 the first method:

< script languate=”javascript”>
   window.location.replace(“//www.jb51.net”);
< / script>

 The second method:

< script languate=”javascript”>   
window.location=”//www.jb51.net”;
< /script>

 The third method:

< script languate=”javascript”>
  document.location.href(“//www.jb51.net”);
< / script>

 The fourth method:

   back (), go () history object methods .go () method requires a shaping parameter entry

<A href = "javascript: history.go (-1)" rel = "external nofollow"> return to the previous </ a>

    or

<A href = "javascript: history.back ()" rel = "external nofollow"> return to the previous </ a>

   Both equivalents are Back

 

  The fifth method:

= document.formName.action "test.jsp";
document.formname.submit ();
ways to use JS // submitted by this method is not recommended

  Sixth method:

< script language=”javascript”>    
window.navigate(“top.jsp”);
< /script>

There are many methods of using the JS jump page, in which only a few are listed for your reference, thank you.

 

·············

st.getRequestDispatcher ( "jump page"); 
Request may pass

Guess you like

Origin www.cnblogs.com/05-hust/p/12403904.html