# Token Examples

These examples illustrate Struts build in support of using tokens to prevent double post.

You have a web page where user can input data and press a button to submit. There could be a problem that the user submit the data many times, by either clicking the button many times, or use the browser back button and then submit the form again.
A good solution is to use a hidden token in the form. The token is autogenerated and unique from time to time. This token is then validated with the HttpSession that it is the first time it is submitted, if not we have a double post and therefore can prevent the second submit action.

For more information check out javadoc for org.apache.struts2.interceptor.TokenInterceptor and org.apache.struts2.interceptor.TokenSessionStoreInterceptor.

Example 1 (token based .jsp example)
Example 2 (as example 1 with redirect after post)
Example 3 (token-session based .jsp example)
Example 4 (token based freemarker example)