struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Labey Sébastien <>
Subject RE: [Strust2] how does Interceptor work?
Date Wed, 27 Sep 2006 12:25:01 GMT
Thanks for your help. I've read these pages and I better understand how it works. I've to try
this further now...
You said I could post my Interceptor to the list, but for the moment it doesn't really exist...
It is only an idea to have an Interceptor that belongs to my default Interceptor stack and
that give acces to before() and after() methods in all Action whatever the method that is
called in the Action. So I could add some work to do before and/or after the execute() method
(or create() or update() or read()...) if needed without having to modify the Interceptors
discribed in the struts.xml for the specific action. All actions could extend these before()
and after() methods only if needed.
One other solution would be to describe a "mother" Action class that would call before() and/or
after() methods of the Action class called during the execute() method... not sure that it
is very clear...
Maybe there is a better way?

-----Message d'origine-----
De : David Evans []
Envoyé : mardi 26 septembre 2006 18:42
À : Struts Users Mailing List
Objet : Re: [Strust2] how does Interceptor work?


These webwork and xwork doc pages may help:

Passed in to your interceptor's intercept method is an ActionInvocation.
This object has a getProxy() method, which returns an ActionProxy.
The ActionProxy has a getMethod() method, which will return the method
name as a String. So you'll need to call those methods and then use
reflection to call your beforeXXX and afterXXX methods.

In your intercept method the invocation.invoke() line is what continues
down the chain of interceptors and finally to the Action's method.
Anything you do before the invocation.invoke() is before the action
execution, anything after invocation.invoke is after the action
execution. It is also after the result execution, so for your case it
seems you'd have to setup the PreResultListener, and put the ActionProxy
method lookup and reflective call bit in there as well.

If you post your Interceptor to the list, that might help also.


On Tue, 2006-09-26 at 12:11 +0200, Labey Sébastien wrote:
> Hi, I'm new to Struts2 and i don't really understand how does Interceptor technique work.

> I have made my own interceptor that implements Interceptor interface. I place it in struts.xml
with my action. It's OK, before invoking my action, i go through my interceptor in the intercept()
> But do all interceptor classes go only through intercept() method or is there a solution
to go through another method name? My need is to go through a beforeXXX() method depending
on the name of the méthod described in struts.xml for my current navigation.
> My second question is how to go through an interceptor after the action has been executed
but before "forwarding" to jsp? I read in documentation that my interceptor has to implements
PreResultListener interface, so i made it, but nothing appens. I dont go through the beforeResult()
method, neither the intercept() method... Is it possible to have only one interceptor for
both the beforeXXX() and the afterXXX() methods?
> All your helps would be great. Thanks in advance
> Sebastien
> Sébastien LABEY
> Division Immobilier
>  <>
> 20, chemin du Randin - B1 - 69130 Ecully
> P Avant d'imprimer, ayez une pensée pour notre environnement
> *

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message