Principle: The token interceptor of struts2 is an interceptor for repeated submissions. The implementation is: adding a token tag to the form, as follows:
1 <form action="user" method="post"> 2 name:<input name="name"> 3 age:<input name="age"> 4 <input type="submit" value="add"> 5 <s:token></s:token> 6 </form>
A hidden tag will be found in the static page returned by the server, and a random code will be generated in this tag, which will be added to the session. When the entire page is submitted, it will be deleted in the session. When submitting, this object cannot be found in the session, thereby avoiding repeated submissions.
The configuration in struts.xml is as follows:
<package name="test" namespace="/" extends="struts-default"> <action name="input" class="com.wbs.InputAction"> <result>/input.jsp</result> </action> <action name="user" class="com.wbs.UserAction"> <result>/addOK.jsp</result> <interceptor-ref name="defaultStack"></interceptor-ref> <interceptor-ref name="token"></interceptor-ref> <result name="invalid.token">/error.jsp</result> </action> </package>