s c h e m a t i c s : c o o k b o o k

/ Cookbook.WebPostRedirectGet

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

The Post-Redirect-Get Pattern

Problem

When displaying a page after receiving a form submission, the browser's "refresh" button should not repost the form results.

Solution

The "Post-Redirect-Get" pattern, or PRG, is a popular web idiom for displaying a page after receiving a form ("POST") submission. The only action performed by the response to form submission is to redirect to an ordinary ("GET") page. This can be abstracted particularly nicely in PLT Scheme with the following simple procedure:

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

Now client code can simply apply this procedure after a form submission to redirect users to a "GET" page:

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

Discussion

Note that the redirect/get procedure returns the request object as a result of the "GET" interaction, though most of the time there won't be any interesting information in this request object that wasn't already in the result of the "POST".

My first implementation was as a special form, implemented as a simple macro whose subexpressions are evaluated in the context of the redirected GET page:

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

(This solution makes use of the send/suspend/dispatch procedure discussed in WebDispatchOnLink.)

However, I believe the solution using send/suspend is even easier to use and understand as a library procedure.

See also:

http://www.theserverside.com/articles/article.tss?l=RedirectAfterPost


Comments about this recipe

Contributors

-- DaveHerman - 30 Sep 2005

Changed to the simpler implementation with send/suspend.

-- DaveHerman - 02 Oct 2005

CookbookForm
TopicType: Recipe
ParentTopic: WebRecipes
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest