[] Struts2 form to prevent duplicate submission

I. Overview

  • regist.jsp----->RegistServlet
  • Form to repeat hazards: brush votes, re-registered, to bring pressure to access server (Denial of Service)
  • solution:
    • Generating a token in the page (that is a random string), storing it in the session, and in the form carries.
    • On the server side, getting data, will also get a token, the token compare it with session stored in, no problem, delete the session tokens.

Two, Struts2 in solution

  • How to solve struts2 in duplicate form submission:
  • Forms submitted in duplicate to solve struts2, you can use it defines a interceptor.
    xml <interceptor name="token" class="org.apache.struts2.interceptor.TokenInterceptor"/>

Third, the implementation steps

  • 1. on the page requires a token tag, a tag is added to the form <s:token/>, it will generate a token on the page, and present in the form.
  • 2. The need to introduce a token interceptor in the action <interceptor-ref name="token"/>
  • 3. The need to configure the view
    • <result name="invalid.token">/token.jsp</result>
    • by Error message
    • Covering resubmit information struts.messages.invalid.token = you have duplicate form submission, please refresh retry

Guess you like

Origin www.cnblogs.com/haoworld/p/struts2-fang-zhi-biao-dan-zhong-fu-ti-jiao.html