Transferred from: http://blog.sina.com.cn/s/blog_8c38b8b701013zzz.html
(1). Forward () method
Use to Javax.servlet.RequestDispatcher class
RequestDispatcher rd = Getservletcontext (). Getrequestdispatcher ("url");
Rd.forward (Requestvar,requestvar); Passing the entry parameters of the servlet
That
Getservletcontext (). Getrequestdispatcher ("url"). Forward (Requestvar,responsevar);
4 ways to turn server-side servlets:
1.ServletContext Getrequestdispatcher ()
2.ServletContext Getnameddispatcher ()
3.ServletRequest Getrequestdispatcher ()
The 4.ServletResponse Sendredirect () is turned.
Forward methods, because these are more efficient. Use the Servletresponse sendredirect () method only if the forward method is not available.
(2). Response.sendredirect (URL);
is actually to send a special header to the browser, and then by the browser to do the steering, go to the specified page, so when using Sendredirect, the address bar on the browser can see the change of address. The new page cannot handle the PageContext of the old page (Request,response,...) Object.
After Response.sendredirect, you should follow a return;
(3). Automatic jump in HTML language
<meta http-equiv= "Refresh" content= "0;url=" http://www.baidu.com ">
0 is the wait time, if set to 5 indicates that the jump starts after waiting for 5s
............
(4). JavaScript jump
A:
<script languate= "JavaScript" >
Window.location.replace ("http://www.baidu.com");
</script>
B: You can also assign a value directly to the Window.location property, window.location= "url", and a is different from a historical record
C:
<script languate= "JavaScript";
Document.location.href ("http://www.google.com");
</script>
for Document,location is not an object, Document.location=document.url
D:history Object Forward (), back (), go () method. The Go () method requires a reshape entry parameter
<a href= "Javascript:history.go ( -1)" > Back to </a>
equivalent to <a href= "javascript: History.back () "> Return to previous </a>
E:
Document.formname.action= "test.jsp";
Document.formName.submit (); How to use JS submission
The first type:
<script language= "javascript" type= "Text/javascript" >
window.location.href= "Login.jsp?backurl=" +WINDOW.LOCATION.HREF;
</script>
The second type:
<script language= "JavaScript" >
Alert ("return");
Window.history.back (-1);
</script>
The third type:
<script language= "JavaScript" >
Window.navigate ("top.jsp");
</script>
The fourth type:
<script language= "JavaScript" >
self.location= ' top.htm ';
</script>
The fifth type:
<script language= "JavaScript" >
Alert ("Illegal access! ");
top.location= ' xx.jsp ';
</script>
(5). <jsp:forward page= "nextpage.jsp"/>
Such as:
<jsp:forward page= "/servlet/login"/>
<jsp:forward page= "/servlet/login" >
<jsp:param name= "username" value= "jsmith"/>
</jsp:forward>
<jsp:forward> tags from one jsp file to another file with a Request object containing the user's requests.
<jsp:forward> tags below the code, will not be executed.
You can use the <jsp:param> tag to transfer parameters and values to the target file, the target file must be a dynamic file and be able to handle the parameters.
If you use a 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 go wrong.
JSP page Jump method meta
1. RESPONSE.SENDREDIRCT ("Jump to Page");
By modifying the header portion of the HTTP protocol, the method redirects the browser to display the content of the redirected Web page. Request cannot pass the value past. The
executes all the code on the page, and then jumps to the page. The Jump Address bar changes. The
can jump to page response.sendredirct (http://www.sun.com) on other servers.
2.response.setheader (); This method, like Response.sendredirect, modifies the header portion of the HTTP protocol.
<% Response.setstatus (httpservletresponse.sc_moved_permanently); String
newlocn= "/index.html"; Response.setheader ("Location", NEWLOCN);
3.<jsp:forward page= "Jump page"/
The method is to use the server-side first output to the buffer mechanism, before the contents of the buffer sent to the client, the original is not sent, instead of sending the contents of the page, if there is a lot of output before <jsp:forward>, the front output has made the buffer full, will be automatically output to the client, then this statement will not work, which should be particularly noted. The
request can pass a value in the past. Jump directly to the page, the following code is not executed. The Address bar does not change after the jump. Cannot jump to a page on another server. The picture is not an absolute path that cannot be displayed.
4.request.getrequestdispatcher ("jump page"); Request can pass the value of the past. Execute all the code on the page before jumping to the page.
The jump Address bar does not change. You cannot jump to a page on another server <% requestdispatcher rd = Request.getrequestdispatcher ("to.jsp"); Rd.forward (Request,response); %> has the following 3 ways to do output redirection: RESPONSE. Setrederect ("URL") This method enables the browser to display the contents of a redirected Web page by modifying the header portion of the HTTP protocol and placing a redirect instruction on the browser.
Response.sendredirect ("http://localhost:7001/index.html");
The following method can also change the HTTP header property, which has the same principle as 1. <%response.setstatus (httpservletresponse.sc_moved_permanently); String newlocn= "/index.html"; Response.setheader ("Location", NEWLOCN); % >
With <JSP:FORWORD>
The method is to use the server-side data output to the buffer mechanism, before the contents of the buffer to send to the client, the original does not send, instead of sending the content of the page, if there is a lot of output before <JSP:FORWORD>, the front output has been full buffer, will automatically output to the client , the statement will not work, and this should be a special note.
I know now. Nested another JSP page in a JSP page, there are three ways:
1, through <%@ include file= "header.jsp"%> this method can only achieve static page loading, most commonly used in a project to implement the general header header.jsp and footer.jsp load.
2, through <%@ include page= "tt.jsp"%> this practice can achieve dynamic page loading, but it needs to pass parameters to the page;
3, through the <iframe src= "JSP path" > To load another JSP page page, is an inline framework. Use forward to pass parameters, write this: <%string str= "You have landed!"; %>
<jsp:forward page= "index.jsp>
<jsp:param name= "name" Value= <%=str%>/>
</jsp:forward>