• Post Reply Bookmark Topic Watch Topic
  • New 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

struts action called on refresh

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My action is inserting data from form into the database.
Now my problem is every time, user hits "refresh" button of browser, the action class is called with existing data and fresh new entry with the same database is made.
Is there any way to get refresh just refresh the data rather than calling the action class?
or at the minimum prevent 'refresh' on the page?

Thanks
Rhishi
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there any way to get refresh just refresh the data rather than calling the action class? or at the minimum prevent 'refresh' on the page?


No. The "Refresh" functionality of the Internet Explorer Web browser cannot be altered or suppressed.

To handle your problem, you need to code the application to not insert identical data into the database. So, if user hits refresh, the application will not process the same data twice.

Alternatively, you can try and fiddle with the page cache of the browser. But, take note that there is no guaranteed method and you'll find conflicting information on how to not cache a page in a specific browser.

The best bet is my first suggestion. Good luck!
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest that you code two different actions: One that performs the database update, and another that prepares the JSP for display. Then create a forward to the second action from the first, specifying redirect="true". Example:

If you do this, the user can press refresh all he wants and all that will happen will be for the display action to be called, not the update action.
[ July 02, 2008: Message edited by: Merrill Higginson ]
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic