Forwarding and redirecting in java
Forward:
request.getRequestDispatcher("success.jsp").forward(request,response);
After the server component receives a user request. After it is processed, it is passed to another component. Do not modify the user's request code. After each component is processed, it is returned to the user, such as the framework of the main page.
User Request-----》Server------》Component 1-------》Component 2------>Server--------》Users
(The request remains unchanged)
Redirect:
response.sendRedirect("success.jsp");
After the server component receives a user request. Modify user request after processing. Return to the user. In this way, the user will passively use the new request using this request again. (Redirection is generally to prevent repeated submissions from being generated after the user submits the data)
User Request-----》Server--------》Component------>Server---------》Users--------》New Request
(Modify user request)
Thank you for reading, I hope it can help you. Thank you for your support for this site!