Struts2中的范围拦截器 [英] Scope interceptor in struts2
问题描述
在Struts2中是否可以看到示例代码?我想将参数从一个动作传递到另一个动作(通过struts.xml配置),要使用范围拦截器.
Is there any sample code where I can see the use of scope interceptor in Struts2? I want to pass a parameter from one action to other action (configured through struts.xml) & want to use scope interceptor.
由于我是Struts 2的新手,任何人都可以提供使用范围拦截器的示例吗?
Since I'm new to Struts 2, can any one provide sample of using scope interceptor?
推荐答案
我相信这在Struts2文档中有很好的描述.她要做的就是
I believe this is very well described in the Struts2 documentation.hers is all you have to do
<action name="scopea" class="ScopeActionA">
<result name="success" type="dispatcher">/jsp/test.jsp</result>
<interceptor-ref name="basicStack"/>
<interceptor-ref name="scope">
<param name="key">funky</param>
<param name="session">person</param>
<param name="autoCreateSession">true</param>
</interceptor-ref>
</action>
<action name="scopeb" class="com.mevipro.test.action.ScopeActionB">
<result name="success" type="dispatcher">/jsp/test.jsp</result>
<interceptor-ref name="scope">
<param name="key">funky</param>
<param name="session">person</param>
<param name="autoCreateSession">true</param>
</interceptor-ref>
<interceptor-ref name="basicStack"/>
</action>
您需要注意的是,您在ActionA中有一个getter,在actionB中有一个类似的setter.另外,您应该使用关键参数来确保您告诉Struts2哪个操作获取了哪些对象
All you need to take care is that, you have a getter in ActionA and and a similar setter in actionB. Also, you should use a key parameter to make sure you tell Struts2 which action gets which objects
阅读此官方文档以了解详细信息 Struts2范围拦截器
read this official documentation for detail Struts2 Scope Interceptor
仅当我必须开发像功能这样的向导时,我才会选择Scope Interceptor,因为它可以处理会话级锁定之类的其他事情. 如果这不是您的要求,则可以通过其他方式传递参数,例如将对象放入会话中,并在第二次操作时从会话中获取对象
I will prefer Scope Interceptor only when i have to develop a wizard like functionality as it will handle other things like session-level locking. If this is not your requirement there are other way to pass parameters like putting object in Session and getting object from session at second action
这篇关于Struts2中的范围拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!