. RequestDispatcher. forward () </P>
It works on the server. When forward () is used, the Servlet engine transmits the HTTP request from the current Servlet or jsp (preferred for SUN Enterprise applications) to another Servlet, jsp (preferred for SUN Enterprise Applications) or common HTML files, that is, your form is submitted to. jsp (the first choice for SUN Enterprise applications), in. jsp (the preferred choice for SUN Enterprise Applications) uses forward () to redirect to B. jsp (the first choice for SUN enterprise-level applications). At this time, all information submitted by form is in B. jsp (preferred for SUN Enterprise Applications) can be obtained, and parameters are automatically transmitted. </P>
However, forward () cannot be redirected to a jsp file with a frame (preferred for SUN Enterprise applications), and can be redirected to an html file with a frame. At the same time, forward () cannot be passed with parameters at the end, for example, servlet? Name = frank. You can use response. setAttribute ("name", name) in the program to upload data to the next page. </P>
The URL in the browser address bar remains unchanged after redirection. </P>
For example, redirection in a servlet File
CODE </P>
Public void doPost (HttpServletRequest request, HttpServletResponse response) </P>
Throws ServletException, IOException </P>
{</P>
Response. setContentType ("text/html; charset = gb2312"); </P>
ServletContext SC = getServletContext (); </P>
RequestDispatcher rd = null; </P>
Rd = SC. getRequestDispatcher ("/index. jsp (preferred for SUN Enterprise Applications)"); </P>
Rd. forward (request, response );
} </P>
2. response. sendRedirect () </P>
It works on the user's browser. sendRedirect () can be passed with parameters, such as servlet? Name = frank is uploaded to the next page and can be redirected to different hosts. the URL of the redirected page appears in the address bar of the browser. </P>
SendRedirect () can redirect jsp files with frames (preferred for SUN Enterprise Applications). </P>
For example, redirection in a servlet File
CODE </P>
Public void doPost (HttpServletRequest request, HttpServletResponse response) </P>
Throws ServletException, IOException </P>
{</P>
Response. setContentType ("text/html; charset = gb2312"); </P>
Response. sendRedirect ("/index. jsp (preferred for SUN Enterprise Applications)"); </P>
}
</P>