Differences between Java forwarding and redirection and example code

Forwarding and redirection in Java

forward:

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

After the server component receives the user request. After its processing, some are passed to another component. The user's request code is not modified. After each component is processed, it is returned to the user, such as the frame of the main page.

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

(request unchanged)

Redirect:

response. sendRedirect("success.jsp");

After the server component receives the user request. User requests are processed and modified. Return to the user in. In this way, if the user uses the request again, he will passively use the new request. (redirection is generally used to prevent repeated submission after users click browser refresh or back after submitting data)

User request -------- server -------- component -------- server -------- user -------- new request

(modify user request)

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

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>