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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic