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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:
  • 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
 
We begin by testing your absorbancy by exposing you to this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
    Bookmark Topic Watch Topic
  • New Topic