Domanda

I want to use a struts2 interceptor for all actions which start with the specific name:

Say I want to intercept all actions which start with Module. Is there any way I can configure an interceptor something like the Spring AOP does e.g: com.acme.web.actions.Module*

I can't use AOP because it breaks all page params (As I guess there is no way the params interceptor is invoked there).

is this possible?

È stato utile?

Soluzione

In Struts you can define different interceptor stacks and apply different stacks to different actions.

So in your situation you can define a different stack like this:

<interceptors>
  <interceptor name="myInterceptor" class="com.company.security.MyInterceptor"/>
  <interceptor-stack name="myStack">
    <interceptor-ref name="myInterceptor"/>
    <interceptor-ref name="defaultStack"/>
  </interceptor-stack>
</interceptors>

And, using wildcard mappings, the configuration bellow is essentially "map all actions named ModuleSomething to a class com.acme.web.actions.ModuleSometing, and apply myStack of interceptors to it:

<action name="Module*" class="com.acme.web.actions.Module{1}">
  <result>{1}.jsp</result>
   <interceptor-ref name="myStack"/>
</action>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top