Java 在Struts中使用Token
我有一个问题,当我在我的应用程序中点击两次链接时,我完成了两次调用,页面刷新了两次,出现了一些错误 所以我决定使用令牌会话拦截器来防止这种错误的发生 我试图在我的应用程序中添加struts 2 tokenSession拦截器,但我遇到了一个问题 我已将此拦截器与所有其他拦截器一起添加:Java 在Struts中使用Token,java,ajax,struts2,token,Java,Ajax,Struts2,Token,我有一个问题,当我在我的应用程序中点击两次链接时,我完成了两次调用,页面刷新了两次,出现了一些错误 所以我决定使用令牌会话拦截器来防止这种错误的发生 我试图在我的应用程序中添加struts 2 tokenSession拦截器,但我遇到了一个问题 我已将此拦截器与所有其他拦截器一起添加: <interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/&g
<interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
我不明白为什么,但这一行Result-Result=savedInvocation.getResult()
始终返回null,因此如果您阅读struts代码;我的操作从未完成,我的页面也从未刷新过(请记住,这是一个ajax调用,所以只需要刷新页面的一部分)
有人能帮我理解为什么我的结果是空的吗?我在配置中忘了什么吗
非常感谢
编辑#1=>添加mpoStack
<interceptor-stack name="mpoStack">
<interceptor-ref name="exception" />
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<!--<interceptor-ref name="debugging" />-->
<!--<interceptor-ref name="profiling" />-->
<!-- Stack d'interceptor sécurité de Marco Polo - Start -->
<interceptor-ref name="securiteStack" >
</interceptor-ref>
<!-- Stack d'interceptor sécurité de Marco Polo - End -->
<interceptor-ref name="fileUpload" />
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*</param>
</interceptor-ref>
<!--<interceptor-ref name="conversionError" />-->
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse,execute,retour,annuler</param>
</interceptor-ref>
<interceptor-ref name="jsonValidation"/>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse,execute,retour,annuler</param>
</interceptor-ref>
</interceptor-stack>
<interceptor-stack name="mpoStackApplet">
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="chain" />
<interceptor-ref name="securiteStack" />
</interceptor-stack>
<!-- QC#3040 PATROL : web.log : Infinite recursion detected -->
<interceptor-stack name="ErrorStack">
<interceptor-ref name="exception" />
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<interceptor-ref name="fileUpload" />
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*</param>
</interceptor-ref>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse,execute,retour,annuler</param>
</interceptor-ref>
<interceptor-ref name="jsonValidation"/>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse,execute,retour,annuler</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mpoStack" />
道场\*
输入、返回、取消、浏览、执行、返回、取消
输入、返回、取消、浏览、执行、返回、取消
道场\*
输入、返回、取消、浏览、执行、返回、取消
输入、返回、取消、浏览、执行、返回、取消
表面上它是(自身与和相关)
如果是这种情况,您可以尝试移动到2.3.20,这是第一个已修复的版本
或者,您可以尝试第一期OP提出的解决方案,即
return savedInvocation.getResultCode();
进入
最后,问题不在于我使用invalidtoken invoken的原因,而在于,正如Roman C在评论中所说的,为什么我在这一点上没有得到有效的标记。因此,我已更正代码以处理有效令牌,现在一切正常。您还可以显示mpoStack定义吗?尝试生成有效令牌,此代码将不会被调用。@AndreaLigios=>我已编辑答案以添加mpoStack;)@RomanC=>为什么它是有效的令牌?我不太明白?你能再解释一下吗?感谢您发布了一个处理无效令牌的代码。删除此代码,或者如果令牌有效,则不应调用此方法。如果该令牌已被此拦截器使用,则该令牌将无效。好的,我现在无法测试,但测试完后,我会验证您的答案;)谢谢谢洛,不,因为问题最终不在这里,谢谢你的帮助,因为如果我面对这个问题,很高兴知道你回答了什么;)Mmok。如果您能找到解决方案,请随时回答您自己的问题,以帮助未来的访问者。如果你觉得这个答案有用的话,也要考虑一下这个问题。
<interceptor-stack name="mpoStack">
<interceptor-ref name="exception" />
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<!--<interceptor-ref name="debugging" />-->
<!--<interceptor-ref name="profiling" />-->
<!-- Stack d'interceptor sécurité de Marco Polo - Start -->
<interceptor-ref name="securiteStack" >
</interceptor-ref>
<!-- Stack d'interceptor sécurité de Marco Polo - End -->
<interceptor-ref name="fileUpload" />
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*</param>
</interceptor-ref>
<!--<interceptor-ref name="conversionError" />-->
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse,execute,retour,annuler</param>
</interceptor-ref>
<interceptor-ref name="jsonValidation"/>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse,execute,retour,annuler</param>
</interceptor-ref>
</interceptor-stack>
<interceptor-stack name="mpoStackApplet">
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="chain" />
<interceptor-ref name="securiteStack" />
</interceptor-stack>
<!-- QC#3040 PATROL : web.log : Infinite recursion detected -->
<interceptor-stack name="ErrorStack">
<interceptor-ref name="exception" />
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<interceptor-ref name="fileUpload" />
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*</param>
</interceptor-ref>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse,execute,retour,annuler</param>
</interceptor-ref>
<interceptor-ref name="jsonValidation"/>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse,execute,retour,annuler</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mpoStack" />
return savedInvocation.getResultCode();
// Checks if the saved invocation has been executed as of now.
// If not it gets executed again.
if(savedInvocation.isExecuted()) {
return savedInvocation.getResultCode();
} else {
return savedInvocation.invoke();
}