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
(Based on Junilu's nice description at https://coderanch.com/t/48839/Struts/Preventing-multiple-posts)

On initial request:

  • call saveToken(request) in your Action class
  • forward to the JSP displaying the form


  • On form submit:

  • have the Action check if isTokenValid(request)
  • if true, process request then call resetToken(); otherwise, we're dealing with a double-submit and will skip processing it.


  • What's happening under the hood:

  • Struts will generate a unique value (the token) and keep it in the session context
  • When the JSP is rendered, Struts inserts the token as a hidden field
  • The hidden field token is submitted along with the rest of the form and isValidToken() checks the value that came in with the current request against the value that was saved in the session context by the most recent saveToken() call. If the two token values match, the submission is valid.


  • << Back to StrutsFaq
     
    And when my army is complete, I will rule the world! But, for now, I'm going to be happy with 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