[英]Redirecting to a correct action after authentication interceptor in Struts 2
I'm using Struts 2 and I have a private package of actions, because certain actions require login to be accessed.我正在使用 Struts 2 并且我有一个私有的操作包,因为某些操作需要登录才能访问。 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.当然还有其他动作定义。
My problem is the following:我的问题如下:
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).他点击
personalArea
链接,他将被自动重定向到登录页面(因为personalArea
是一个安全操作)。 What I want is: after login user is automatically redirect (to continue the action) to personalArea
and not home page.我想要的是:登录后用户自动重定向(以继续操作)到
personalArea
而不是主页。
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.所以,我想要的是:当用户由于安全操作登录系统时,登录后操作(安全)的执行继续。
How can I do that?我怎样才能做到这一点?
One of the possible solutions is to keep track of the user intercepting their URLs.一种可能的解决方案是跟踪用户拦截他们的 URL。 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}")
})
after login check the session for savedUrl
and return result "return"
.登录后检查会话的
savedUrl
并返回结果"return"
。 Assumed providing getter for the dynamic parameter.假设为动态参数提供 getter。
At the end I was able to make it work.最后我能够让它工作。 Basically what I missed from the solution proposed by Roman C. was that I need to have a class variable saved (so not only have it in the session).
基本上我从 Roman C. 提出的解决方案中错过的是我需要保存一个类变量(所以不仅在会话中保存它)。
private String savedUrl;私人字符串savedUrl;
public String getSavedUrl(){
return savedUrl;
}
That did the trick.这就是诀窍。
Thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.