只要用户在当前会话中,防止两次调用相同的操作 [英] Prevent same action called twice as long as user is in current session
问题描述
我正在使用Struts2框架,我的问题是
I am using Struts2 framework, my problem is
如果用户登录系统并单击某些操作,例如说ACTION1
,则流程将转到操作类并执行某些方法,并返回适当的结果.
他可能会访问某些网页,然后再次单击ACTION1
.
If user log-in into system and clicked some action lets say ACTION1
, flow will go to action class and executes some method, return appropriate result.
He may visit some of the web pages, and again clicked ACTION1
.
只要他在同一个会话中,现在控件就不应使用该特定方法,但结果应与以前的结果相同.
As long as he is in the same session, now the control should not go that particular method but the result should be same as previous results.
我们如何实现这一目标?
How can we achieve this?
推荐答案
You can try a tokenSession
interceptor.
此拦截器基于
Token
拦截器构建,提供 用于处理无效令牌的高级逻辑.与普通令牌不同 拦截器,此拦截器将尝试提供智能 如果使用同一会话的多个请求发生故障转移. 也就是说,它将阻止后续请求,直到第一个请求被执行为止. 完成,然后不返回invalid.token
代码,而是 会尝试显示与原始有效信息相同的响应 如果没有多个请求,则将显示操作调用 首先提交.
This interceptor builds off of the
Token
Interceptor, providing advanced logic for handling invalid tokens. Unlike the normal token interceptor, this interceptor will attempt to provide intelligent fail-over in the event of multiple requests using the same session. That is, it will block subsequent requests until the first request is complete, and then instead of returning theinvalid.token
code, it will attempt to display the same response that the original, valid action invocation would have displayed if no multiple requests were submitted in the first place.
It will prevent from double submit the same action or reuse the same token that you provide with s:token
tag.
说明
停止重复提交表格.
Description
Stop double-submission of forms.
令牌标记用于帮助双击"提交
问题.如果您使用TokenInterceptor
或
TokenSessionInterceptor
. s:token
标签只是放置一个隐藏的
包含唯一令牌的元素.
The token tag is used to help with the "double click" submission
problem. It is needed if you are using the TokenInterceptor
or the
TokenSessionInterceptor
. The s:token
tag merely places a hidden
element that contains the unique token.
将标记放置在表单中,您再也不会两次提交相同的表单.令牌会话拦截器将通过返回与第一种情况相同的响应来尝试为您处理无效令牌.
Place the tag inside your form and you never get back in submitting the same form twice. Token session interceptor will try to handle invalid token for you by returning the same response like in first case.
这篇关于只要用户在当前会话中,防止两次调用相同的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!