java forwarding and redirection distinction and instance code

  • 2020-05-17 05:29:44
  • OfStack

Forwarding and redirecting in java

Forwarding:

request.getRequestDispatcher("success.jsp").forward(request,response);

After the server component receives the user request. It is processed and then passed to another component. Do not modify the user's request code. Each component is then returned to the user, such as the main frame.

User request -- server -- component 1-- component 2-- > Server -- user

(request unchanged)

The redirection:

response.sendRedirect("success.jsp");

After the server component receives the user request. Modify the user request after processing. Back to the user. The user then USES the request again and passively USES the new request. (redirection 1 is generally used to prevent repeated submissions after the user submits the data by clicking on the browser refresh or clicking backward)

User request -- server -- component -- > Server -- "user --" new request

(modify user request)

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: