Domanda

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.

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). 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.

How can I do that?

È stato utile?

Soluzione

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}")
})

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

Altri suggerimenti

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).

private String savedUrl;

public String getSavedUrl(){
    return savedUrl;
}

That did the trick.

Thanks

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top