How to transfer data from Interceptor to URL and JSP?

I have an authenticator that checks if a user is registered. If it is not redirected to the login page, with the "url" parameter of the query string indicating the referrer URL. I tried using "actionInvocation.getInvocationContext (). GetParameters ()" to pass the values ​​of the redirect URL, but no luck.

Can anyone suggest what I did wrong? Many thanks.

Interceptor Code:

public String intercept(ActionInvocation actionInvocation) throws Exception {
    Map session = actionInvocation.getInvocationContext().getSession();
    Map params = actionInvocation.getInvocationContext().getParameters();

    String user = (String) session.get(Constants.KEY_USER);

    boolean isAuthenticated = (null!=user);

    if (!isAuthenticated) {
        params.put("backUrl", "http://www.some_url.com/");
        return Action.LOGIN;            
    }
    else {
        return actionInvocation.invoke();
    }
}

struts.xml parts

<global-results>
   <result name="login" type="redirect">/login?url=${backUrl}</result>

+3
source share
1 answer

struts.xml; params :

 <interceptor-stack name="defaultLoginStack">
      ...
      <interceptor-ref name="params" />
      <interceptor-ref name="login" />
      ...
 </interceptor-stack>

- javax.servlet.forward.query_string:

 String queryString = (String) actionInvocation.getRequest().
      getAttribute("javax.servlet.forward.query_string");
0

Source: https://habr.com/ru/post/1764125/


All Articles