在Struts 2 - 重定向到一个正确的动作验证后的拦截 [英] Struts 2 - Redirecting to a correct action after authentication interceptor

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

问题描述

我无法在网上找到的任何东西,所以我会在这里提问。我使用strut2,我有行动的私人包,导致某些操作需要登录访问被。所以,我有这在我的安全包:

I couldn't find anything online so I'll ask here. I'm using strut2 and I have a private package of actions, cause certain actions require login to be access. 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.

我怎么能这样做?

推荐答案

一个可能的解决方案是跟踪用户拦截网址中。你可以做到这一点的验证拦截器。

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 会话并返回结果重返。承担了动态参数提供的getter。

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

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

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