Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

struts action called on refresh  RSS feed

 
rhishi fansalkar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • 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!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!