After logout back/reload issue in Struts 2

随声附和 提交于 2019-12-08 21:42:33

The problem is that after logout you are not actually redirect to a new action. The cause of such behavior when you pressed the back button you got a conformation dialog in the browser. The back button is not used to call an action, unless it's not invoked via triggering it using Ajax. You should follow post-redirect-get pattern when doing request for logout.

<action name="logout" class="com.struts2.LoginAuthentication" method="logout">
    <interceptor-ref name="clear-cache" />
    <result name="success" type="redirect">/</result>
    <result name="error">/error.jsp</result>
</action> 

I resolved the issue by redirecting it to another action. and wrote another interceptor to validate if it is having user id in the session or not.

<default-interceptor-ref name="loginStack"></default-interceptor-ref>
<action name="login" class="com.struts2.LoginAuthentication"
            method="execute">
            <interceptor-ref name="defaultStack"/>
            <result name="manager" type="redirectAction">
            <param name="actionName">home</param>
            </result>
</action>
<action name="home" class="com.struts2.LoginAuthentication"
            method="home">
            <result name="success">/ManagerView.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!