Scope interceptor in struts2

老子叫甜甜 提交于 2019-12-02 13:31:43

问题


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.

Since I'm new to Struts 2, can any one provide sample of using scope interceptor?


回答1:


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>

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

read this official documentation for detail Struts2 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



来源:https://stackoverflow.com/questions/8441702/scope-interceptor-in-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!