1

ログインページがあります。ログインのリクエストは、複数のアクション クラスから送信される可能性があります。ユーザーが検証されたら、前のアクション クラス (ログイン要求の元) にリダイレクトする必要があります。これを行うためにインターセプターを使用しています。しかし、私は何かを見逃しており、適切にリダイレクトできません。

これが私のコードです:

public class SetTargetInterceptor extends MethodFilterInterceptor implements
    Interceptor {
private static final long serialVersionUID = 1L;

public String doIntercept(ActionInvocation invocation) throws Exception {
    Object action = invocation.getAction();
    HttpServletRequest request = (HttpServletRequest) invocation
            .getInvocationContext().get(StrutsStatics.HTTP_REQUEST);
    if (action instanceof TargetAware) {
        TargetAware targetAwareAction = (TargetAware) action;
        if (targetAwareAction.getTarget() == null)
            targetAwareAction.setTarget(getCurrentUri(request));
    }
    return invocation.invoke();
}

private static String getCurrentUri(HttpServletRequest request) {
    String uri = request.getRequestURI();
    String[] arr = org.apache.commons.lang3.StringUtils.split(uri, "/");
    for (int i = 0; i < arr.length; i++) {
        System.out.println(arr[i]);
    }
    if (arr != null && arr.length > 0) {
        int len = arr.length;
        uri = arr[len - 1];
    }

    String queryString = request.getQueryString();

    if (queryString != null && !queryString.equals(""))
        uri += "?" + queryString;
    return uri;

}

public void init() { /* do nothing */
}

public void destroy() { /* do nothing */
}

私のstruts.xml

<interceptors>  
<interceptor name="setTargetInterceptor" 
class="com.markEffy.aggregator.interceptors.SetTargetInterceptor"></interceptor>

     <interceptor-stack name="newStack">
        <interceptor-ref name="setTargetInterceptor"/>
    <interceptor-ref name="defaultStack" />
      </interceptor-stack>

</interceptors>
 <action name="login" 
        class="com.markEffy.aggregator.web.LoginAction" 
        method="login">
  <result name="success"  type="redirect">
  <param name="location">${target}</param>
  <param name="parse">true</param>
   </result>
 <action name="reload" 
        class="com.markEffy.aggregator.web.PathFinderAction" 
        method="execute">
         <interceptor-ref name="newStack"/>
        <result name="success">/results.jsp</result>
  </action>

PathFinderActionログインを要求できます。loginActionユーザーの検証に使用されます。

4

1 に答える 1

0

ターゲット アクションの URL に動的パラメーターを使用するグローバルな結果がありません。

<global-results>
    <result name="return" type="redirect">${target}</result>
</global-results> 

この結果は、インターセプターまたは を実装するアクションから返すことができますTargertAware。プロパティにはtarget、結果によって呼び出される getter が必要です。

于 2015-03-08T15:25:48.660 に答える