0

I have a few simple actions:

<action name="edit" class="EditAction">
  <result>/WEB-INF/jsp/form.jsp</result>
</action>

<action name="preview" class="PreviewAction">
  <result>/WEB-INF/jsp/preview.jsp</result>
  <result name="input">/WEB-INF/jsp/form.jsp</result>
</action>

<action name="store" class="StoreAction">
  <result>/WEB-INF/jsp/confirmation.jsp</result>
  <result name="input">/WEB-INF/jsp/preview.jsp</result>
</action>

<global-results>
  <result name="invalid.token">/WEB-INF/jsp/invalidToken.jsp</result>
</global-results>

and classic scenario: user interacts with text inputs, press Save, view a Preview page and press Save on it to save data, without double-press buttons, refreshing page etc.

Why double submit can occurs in such situation?

4

1 回答 1

1

即使我在浏览器刷新时在 struts2 中遇到双重表单提交问题。我使用 post-redirect-get 模式解决了这个问题,以避免重复或重复的表单提交。发生这种情况是因为根据 POST 请求为响应点击“刷新页面”将重新发出 POST 请求。即使按下双按钮,它也会重复您为到达当前页面所做的操作。struts2 中的成功和错误都会发生这种情况。我建议您在必要时进行此更改。

<action name="onStoreRedirect">
  <result name="success" type="redirect">store</result>
</action>

<action name="store" class="StoreAction">
  <result>/WEB-INF/jsp/confirmation.jsp</result>
  <result name="input">/WEB-INF/jsp/preview.jsp</result>
</action>
于 2012-12-18T09:11:02.710 回答