Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
    Bookmark Topic Watch Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis
  • Mark post as helpful
  • send pies
  • Report post to moderator
The following is a simple example of a JSP page that uses the Post-Redirect-Get (PRG) pattern.

It uses scriptlets for backward compatibility and to allow the entire pattern to be written in a single JSP page. Note: this does not mean that you should use scriptlets in your pages. It is done here for illustration purposes only!

Lines 1 through 16 simulate typical database read/write operations by reading and appending to a string of text (comments) bound to session scope.

The key to implementing the PRG pattern is to insure that a page is never displayed as a result of a request of type POST. Here, this is done by redirecting to a read-only version of the page after performing a database write (line 16).

To test, copy this page (without the line numbers) into your application and access it through the browser. Add a comment and then click the refresh button. Note that the previous write operation has not been repeated.





Also see DoubleSubmitProblem
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!