2

私はワイルドカードでこのアクションを持っています:

@Namespace("/posts")
public class SearchPostBeansAction extends ActionSupport{
    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(SearchPostBeansAction.class); 
    
    @Override
    @Actions({
        @Action(value="/{search1}/{param1}/",results={ 
            @Result(name=ACTION_SUCCESS,location="classic.main.general", type="tiles")})    
    })
    public String execute() throws Exception {
           logger.info("Action: " + getInvocatedURL() );
           String forward = SUCCESS;
           logger.info("getSearch1( " + getSearch1() + " )");
           logger.info("getParam1( " + getParam1() + " )");
           return forward;
    }
}

実行された結果:

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) - Action:
   /posts/category/cars/
   
 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getSearch1( category )

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getParam1( cars )

そのアクションを傍受した場合:

@InterceptorRef("seoFilter")
@Namespace("/anuncios")
public class SearchPostBeansAction extends ActionSupport{
    private static final long serialVersionUID = 1L;
...
}

実行された結果:

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) - Action:
   /posts/category/cars/
   
 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getSearch1( null )

 - INFO (com.silver.front.view.actions.SearchPostBeansAction) -   
   getParam1( null) 

ワイルドカードのパラメータが失われたのはなぜですか?

ここにインターセプターがあります:

public class SEOFilter implements Interceptor{
    private static final long serialVersionUID = 1L;
    private static Logger logger = Logger.getLogger(SEOFilter.class); 
    
    ActionSupport actionSupport = null;
    
    public String intercept(ActionInvocation invocation) throws Exception {
        actionSupport = (ActionSupport) invocation.getAction();
        actionSupport.execute();
    }
}
4

3 に答える 3

1

エラーは@InterceptorRef("seoFilter")、アクション クラスに適用されたものであり、慣例により、クラス内のすべてのアクションに適用されることを知っておく必要があります。これを削除し、アクションにカスタム インターセプターを追加する場合は、@Actionアノテーションを使用します。

@Action(value="/{search1}/{param1}/", results={ 
        @Result(name=ACTION_SUCCESS,location="classic.main.general", type="tiles")},
   interceptorRefs={@InterceptorRef("seoFilter"),@InterceptorRef("defaultStack")
})    

seoFilterスタックを壊さない有効なインターセプターであると仮定します。

これは有効なインターセプターのコードです

public String intercept(ActionInvocation invocation) throws Exception {
    // here you can place the code that used to intercept the action
    ...
    //finally
    return invocation.invoke();
}

を投稿しておらずstruts.xml、ワイルドカード マッピングを使用するように Struts を構成した方法がわからないため、ドキュメンテーション ページから高度なワイルドカードのリファレンスを提供して、自分で行うことができます。

于 2014-03-08T10:53:53.240 に答える