Jump in JSP:
(1). Forward () method
Use the javax. servlet. requestdispatcher class
Requestdispatcher RD = getservletcontext (). getrequestdispatcher ("url ");
Rd. Forward (requestvar, requestvar); // pass the servlet entry Parameter
/* The forward function has passed the request and response object of the original page into the new page. Therefore, the new and old pages have the same request and response object. Request. getparameter ("Var") to get the corresponding value .*/
/* Forward () is directly implemented on the server. The browser does not know or deal with the browser, and the address of the browser does not change. */
That is:
Getservletcontext (). getrequestdispatcher ("url"). Forward (requestvar, responsevar );
Four Methods for server-side servlet redirection:
1. getrequestdispatcher () of servletcontext ()
2. getnameddispatcher () of servletcontext ()
3. getrequestdispatcher () of servletrequest ()
4. servletresponse's sendredirect () is switched.
Forward method, because these are more efficient. Use the sendredirect () method of servletresponse only when the forward method is unavailable.
(2). response. sendredirect (URL );
In fact, it is to send a special header to the browser, and then turn to the specified page, so when sendredirect is used, the address changes can be seen on the browser's address bar. The new page cannot process the pagecontext (request, response,...) object of the old page.
After response. sendredirect, follow the return statement;
(3). Automatic jump of HTML language
<HTML>
<Head>
<Meta http-equiv = "refresh" content = "0; url =" http://www.baidu.com ">
0 indicates the waiting time. If it is set to 5, the jump starts after 5s.
</Head>
............
(4) JavaScript redirection
A: <SCRIPT effecate = "JavaScript">
Window. Location. Replace ("http://www.baidu.com ");
</SCRIPT>
B: You can also assign values to the window. Location attribute. Window. Location = "url" is different from a in that it has historical records.
C: <SCRIPT effecate = "JavaScript">
Document. Location. href ("http://www.google.com ");
</SCRIPT>
For document, location is not an object, document. Location = Document. url
D: The forward (), back (), go () method of the history object. Go () method requires an integer entry parameter.
<A href = "javascript: history. Go (-1)"> return to the previous step. </a>
It is equivalent to <a href = "javascript: history. Back ()"> returning to the previous step </a>
E: Document. formname. Action = "test. jsp ";
Document. formname. Submit (); // submit using JS
First:
<Script language = "JavaScript" type = "text/JavaScript">
Window. Location. href = "login. jsp? Backurl = "+ window. Location. href;
</SCRIPT>
Second:
<Script language = "JavaScript">
Alert ("return ");
Window. History. Back (-1 );
</SCRIPT>
Third:
<Script language = "JavaScript">
Window. navigate ("Top. jsp ");
</SCRIPT>
Fourth:
<Script language = "JavaScript">
Self.location+'top.htm ';
</SCRIPT>
Category 5:
<Script language = "JavaScript">
Alert ("illegal access! ");
Top. Location = 'xx. jsp ';
</SCRIPT>
(5). <JSP: Forward page = "nextpage. jsp"/>
For example:
<JSP: Forward page = "/servlet/login"/>
<JSP: Forward page = "/servlet/login">
<JSP: Param name = "username" value = "jsmith"/>
</Jsp: Forward>
<JSP: Forward> the tag transfers a request object containing user requests from one JSP file to another. <JSP: Forward> the code below the tag cannot be executed.
You can use the <JSP: param> label to transfer parameters and values to the target file. The target file must be a dynamic file and can process parameters.
If you use non-buffered output, be careful when using <JSP: Forward>. If the JSP file already has data before you use <JSP: Forward>, the file execution will fail.
JSP page Jump Methods
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.sun.com) on another server ).
2. response. setheader (); this method is the same as response. sendredirect, by modifying the HTTP header section.
<% 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 output data to the buffer. Before the buffer content is sent to the client, the original content on the page is not sent. If
There are a lot of outputs before <JSP: Forward>, and the previous output will automatically output to the client when the buffer is full. This statement will not work, so 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. After all the code on the page is executed, go to the page.
The jump Address Bar remains unchanged. You cannot jump to the page on other servers <% requestdispatcher RD =
Request. getrequestdispatcher ("to. jsp"); RD. Forward (request, response); %>
There are three ways 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: // localhost: 7001/index.html ");
The following method can also change the HTTP
Header attribute. The principle is the same as that of header 1.
. <% Response. setstatus (httpservletresponse. SC _moved_permanently); string newlocn = "/index.html"; response. setheader ("location", newlocn); %>
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, in <JSP:
Forword> there are a lot of outputs before, and the previous output has filled the buffer and will be automatically output to the client, so this statement will not work, this should be noted.
As you know, you can nest another JSP page in a JSP page. There are three methods: 1. Use <% @ include
File = "header. jsp" %> This method can only Load Static pages. The most common method is to load General header. jsp and footer. jsp in a project.
2. You can use <% @ include page = "TT. jsp" %> to load dynamic pages, but you must pass parameters to the pages. 3. You can use <IFRAME
Src = "JSP path"> to load another JSP page to the page, which is an inline framework.
If you use forward to pass the parameter, enter <% string STR = "you have logged on! "; %>
<JSP: Forward page = "index. jsp> <JSP: Param name =" name "value = <% = STR %>/>
</Jsp: Forward>