Post/Redirect/Get

From Wikipedia, the free encyclopedia

Post/Redirect/Get (PRG) is a common design pattern for web applications, to help avoid duplicate form submissions and allow web applications to behave more intuitively with browser bookmarks and the reload button.

After a web user submits a form to a server, the server typically generates an HTML page as a response. To the user, this looks like an ordinary web page, but because it was generated by an HTTP POST request, it cannot be bookmarked, and attempting to reload/refresh the page in the browser could cause the form information to be resubmitted, possibly with unexpected results (such as a duplicate purchase).

To avoid this problem, many web applications use the PRG pattern — instead of returning an HTML page directly, the POST operation returns a redirection command (using the HTTP 303 response code (sometimes 302) together with the HTTP "Location" response header), instructing the browser to load a different page using an HTTP GET request. The result page can then safely be bookmarked or reloaded without unexpected side effects.


[edit] External links