Request forwarding is, the server receives a request, from a resource to jump to another operation called resource request is forwarded.
servlet 1:
// obtain parameters (work material) to view the request String username = req.getParameter ( "username" ); System.out.println ( "servlet1 view (counter 1) of the parameters (material):" + username); // to a material of the cover section, and transferred to servlet2 (2 counter) to see req.setAttribute ( "key1" "counter Chapter 1" ); // ask: servlet2 (counter 2) how to go / ** * forwards the request must begin with a slash, / slash indicates address: HTTP: // ip : Port / Engineering name / code mapped to the IDEA web directory <br/> // * */ RequestDispatcher requestDispatcher = req.getRequestDispatcher("/servlet2"); //RequestDispatcher requestDispatcher = req.getRequestDispatcher("http://www.baidu.com"); // 走向 Sevlet2 (柜台 2 ) requestDispatcher.forward(req,resp);
Forwarded to the doGet method of servlet2:
// obtain parameters (work material) to view the request String username = req.getParameter ( "username" ); System.out.println ( "view parameters (material) Servlet2 counter 2) (:" + username); // see if there is a counter seal Object req.getAttribute key1 = ( "key1" ); System.out.println ( "Are there Chapter 1 counter:" + key1); // handle their own business System.out.println ( "Servlet2 handle their own business");