【问题标题】:Disabling the back button navigation in Struts 2 without using java script在不使用 java 脚本的情况下禁用 Struts 2 中的后退按钮导航
【发布时间】:2015-06-27 05:41:35
【问题描述】:

我编写了一个自定义拦截器,用于禁用浏览器中的后退按钮功能。但是代码不起作用。我也在 html 中添加了元标记。我不想为此使用 java 脚本。

public String intercept(ActionInvocation invocation) throws Exception {
                final ActionContext actionContext = invocation.getInvocationContext();
                HttpServletResponse response = (HttpServletResponse) actionContext.get(StrutsStatics.HTTP_RESPONSE);
                if(response != null){

                    response.setHeader("Cache-Control", "no-cache, no-store");
                    response.setHeader("Pragma", "no-cache");
                    response.setHeader("Expires", "-1");
                }

                return invocation.invoke();
            }

我可以编写一个自定义拦截器来检查用户会话是否存在,它将重定向到用户单击浏览器后退按钮的同一页面上。

任何建议我如何实施它。

【问题讨论】:

标签: struts2 interceptor


【解决方案1】:

好的,我找到了一个禁用后退按钮功能的解决方案。

我创建了一个名为RedirectAction 的操作,用于检查会话是否存在。如果会话存在,那么它会在主页上重定向用户,否则在登录页面上。

<action name="home" class="com.demo.actions.RedirectAction" method="redirectAtHome">
    <result name="success">home</result>
    <result name="fail" type="redirectAction">
         <param name="actionName">welcome</param>
    </result>
</action>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-09-23
    • 2014-01-16
    • 2011-08-17
    • 2017-08-07
    • 2020-10-15
    • 1970-01-01
    • 2018-11-19
    • 2015-11-07
    相关资源
    最近更新 更多