.RequestDispatcher.forward()</P>
It works on the server side. When using forward(), the 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() to redirect to b.jsp. At this time, all the information submitted by the form can be obtained in b.jsp, and the parameters are automatically passed.</P>
However, forward () cannot redirect to a jsp file with a frame. It can redirect to an html file with a frame. At the same time, forward () cannot be passed with parameters at the end, such as servlet?name=frank. If this does not work, you can pass the response in the program. .setAttribute("name",name) to pass to the next page.</P>
The URL in the browser address bar remains unchanged after redirection.</P>
Example: redirection in 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");</P>
rd.forward(request, response);
}</P>
2.response.sendRedirect()</P>
It works on the user's browser. sendRedirect() can pass parameters, such as servlet?name=frank to the next page. At the same time, it can redirect to a different host, and a duplicate will appear on the browser address bar. The URL of the directed page.</P>
sendRedirect() can redirect jsp files with frames.</P>
Example: redirection in 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");</P>
}
</P>