注销后在Struts 2中重新加载/重新加载问题 [英] After logout back/reload issue in Struts 2

查看:55
本文介绍了注销后在Struts 2中重新加载/重新加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录页面(Index.jsp),这里用户输入了用户ID和密码.在commit LoginAuthentification.java(操作类)上调用并验证用户身份,但是根据操作类中的结果,它返回JSP.

I have a login page (Index.jsp) , here user put user id and password. on submit LoginAuthentification.java(action class) called and authenticate the user , but according to the result in action class it return the JSP.

<action name="login" class="com.struts2.LoginAuthentication"
    method="execute">
    <interceptor-ref name="clear-cache" />
    <result name="manager">/ManagerView.jsp</result>
    <result name="SSE" type="redirectAction">
        <param name="actionName">viewPlan</param>
        <param name="userID">${userID}</param>
    </result>
    <result name="input">/Index.jsp</result>
    <result name="error">/error.jsp</result>
</action>

在这种情况下,它将返回ManagerView.jsp.现在,在此JSP中,我为logout添加了超链接.它正在

In this case, it is returning ManagerView.jsp. Now in this JSP, I added a hyperlink for logout. and it is doing below

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

动作类代码

public String logout() {  
    //if (session instanceof org.apache.struts2.dispatcher.SessionMap) {
    session.clear();
    //session.re
    System.out.println("test");
    session.remove("loggedInUser");
   ((org.apache.struts2.dispatcher.SessionMap) session).invalidate();

    //}  
    return "success";
}

注销后将其重定向到Index.jsp,现在我单击了后退"按钮 它在chrome中显示"confirm form resubmission"消息,并且IE中的网页已过期.但是,当我重新加载页面时,它会自动登录旧用户. 我已添加

after logout it is redirected to Index.jsp, now I clicked on back button It display "confirm form resubmission" message in chrome and webpage expired in IE. But when I reload the page it login the old user automatically. I have added

<%                        
  response.setHeader("Cache-control", "no-cache, no-store");           
  response.setHeader("Expires", "0");
  response.setHeader("Vary", "*");
%> 

在JSP和拦截器中.

我正在尝试在重新加载时阻止自动登录.

I am trying to block auto login on reload.

推荐答案

问题在于,注销后实际上并没有重定向新动作.当您按下后退"按钮时,这种行为的原因是您在浏览器中看到了一个配置对话框.后退按钮不用于调用动作,除非未通过使用Ajax触发它来调用它.在执行注销请求时,您应该遵循 post-redirect-get 模式. >

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> 

这篇关于注销后在Struts 2中重新加载/重新加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆