在Struts 2中的身份验证拦截器之后重定向到正确的操作 [英] Redirecting to a correct action after authentication interceptor in Struts 2

查看:94
本文介绍了在Struts 2中的身份验证拦截器之后重定向到正确的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts 2,并且我有一个私有的操作包,因为某些操作需要登录才能访问.因此,我将其放在我的安全包装中:

I'm using Struts 2 and I have a private package of actions, because certain actions require login to be accessed. So I have this in my secure package:

<interceptors>
    <interceptor name="authenticationInterceptor" class="com.koorde.interceptor.AuthenticationInterceptor"/>
        
    <interceptor-stack name="secureStack">
      <interceptor-ref name="authenticationInterceptor"/>
      <interceptor-ref name="defaultStack"/>    
    </interceptor-stack>
</interceptors>
    
<default-interceptor-ref name="secureStack"/>

<global-results>
    <result name="login" type="redirect">dologin</result>
    <result name="session_error" type="redirect"> html/error/hibernate_session.jsp</result>
    <result name="error" type="redirect"> html/error/hibernate_session.jsp</result>
</global-results>

当然还有其他动作的定义.

And of course other actions definition.

我的问题如下:

假设用户要访问他的个人区域.他单击 personalArea 链接,他将自动在登录页面上重定向(因为 personalArea 是安全的操作).我想要的是:登录用户后自动重定向(继续操作)到 personalArea 而不是首页.

Let's say a user want to access his personal area. He clicks on personalArea link and he will be automatically redirected on login page (cause personalArea is a secure action). What I want is: after login user is automatically redirect (to continue the action) to personalArea and not home page.

因此,我想要的是:当用户由于安全操作而登录系统时,登录后继续执行操作(安全).

So, what I want is: when user log in into the system because of a secure actions, after login the execution of the action (secured) continues.

我该怎么做?

推荐答案

可能的解决方案之一是跟踪用户拦截其URL的情况.您可以在身份验证拦截器中完成此操作.

One of the possible solutions is to keep track of the user intercepting their URLs. You might do it in the authentication interceptor.

String queryString = request.getQueryString();
session.put("savedUrl", request.getRequestURI()+(queryString==null?"":("?"+queryString))); 

使用带有动态参数的全局结果

use the global result with dynamic parameter

@Results({
  @Result(name = "return", type = "redirect", location = "${savedUrl}")
})

登录后,检查会话中的 savedUrl 并返回结果"return" .假定为动态参数提供吸气剂.

after login check the session for savedUrl and return result "return". Assumed providing getter for the dynamic parameter.

这篇关于在Struts 2中的身份验证拦截器之后重定向到正确的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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