The following is a summary of the redirection technology of JSP / servlet.
1.RequestDispatcher.Forward () is a role in the server. When using forward (), servlet Engine passes the HTTP request from the current servlet or JSP to another servlet, JSP, or ordinary HTML file, that is, your Form is submitted to A.JSP, in A.jsp uses Forward () redirect to B.JSP, all information submitted by Form can be obtained in B.JSP, the parameters are automatically passed. But forward () cannot redirect to Frame The JSP file can be redirected to the HTML file with frame, and forward () cannot be passed on the back with parameter, such as servlet? name = frank, this is not, you can pass Response.setattribute ("name", name) To the next page.
Redirect the browser address bar URL unchanged.
Example: Redirect PUBLIC VOID DOPOST (HTTPSERVLETREQUEST REQUEST, HTTPSERVLETREQUEST REESPONSE) THROWS servleTexception, ioException {
Response.setContentType ("text / html; charSet = GB2312");
ServletContext sc = getServletContext ();
RequestDispatcher rd = NULL;
Rd = sc.getRequestDispatcher ("/ index.jsp"); // orientation page
Rd.Forward (Request, Response);
} It is usually used in servlets, not used in JSP.
2.Response.sendredirect () is working in the user's browser, sendRedirect () can be passed, such as servlet? Name = frank to the next page, and it can redirect to different hosts, sendRedirect () You can redirect the JSP file with Frame. The URL Example of Redirects will appear on the browser address bar: Turn public void dopost (httpservletRequest request, httpservletResponse response) on servlets.
Throws ServleTexception, IOException
{
Response.setContentType ("text / html; charSet = GB2312");
Response.sendRedirect ("/ index.jsp");
} Due to the hidden object in the JSP page, you can use Response.sendredirect () directly to replace directly in the JSP page. Note: (1). When using response.sendredirect, there is no HTML output in front. This is not absolute, can't have HTML output, but it does not have HTML to be sent to the browser. In fact, SERVER has a Cache mechanism, usually at 8K (I am JSP Server), which means that unless you shut down cache, or you use out.flush () forced refresh, then before using Sendredirect, There are small amounts of HTML outputs are also allowed. (2) After (2). After. Response.sendredirect, it should be followed by Return; we already know that response.sendredirect is turned through the browser, so it will only have actual actions only after the page processing is completed. Since you have already turned to turn, what is the significance of the post-output? And it is possible that the steering failure is caused by the back of the output. Comparison: (1) .Request Dispatcher.Forward () is the steering of the control over the container, which does not show the turn-behind address in the client browser address bar; (2) .response.sendredirect () is complete Jump, the browser will get the address of the jump and resend the request link. Thus, the link address after the jump is seen from the address bar of the browser. The former is more efficient, when the former can meet the needs, try to use the RequestDispatcher.Forward () method. Note: In some cases, for example, if you need to jump to a resource on a further server, you must use the httpservletResponse.sendRequest () method. 3.
Its underlying portion is implemented by RequestDispatcher, so it comes with a requestDispatcher.Forward () method.
If there is a lot of output before
4. Modify the Location property of the HTTP header to react to the redirection of the page through the settings directly modify the address bar. The JSP file code is as follows:
<% Response.setstatus (httpservletResponse.sc_moved_permanently); string newlocn = "/newpath/jsa.jsp";response.setheader ("Location" ,Newlock);%>
5. JSP Realization After a page stays after a number of seconds, automatically redirects to another page in the HTML file, the following code: Its meaning: The page that is browsing after 5 minutes will automatically change to Target.html. 300 in the code is a refresh delay time, in seconds. Targer.html For the target page you want to turn, if this page is automatically refreshing this page. From the above, you can automatically redirect to another page after you can realize that a page is stopped for several seconds. Key code: String content = staytime "; url =" url; response.setHeader ("refresh", content); if you have a summary, please express your opinion or experience.
Note: Part of some information comes from: http://blog.9cbs.net/doli/archive/2002/11/28/13203.aspx