To quote from the book "Manning: Struts 2 in Action" about interceptors:
"The interceptors are
invoked both before and after the action, though we should note that they actually fire
after the result has executed. Interceptors don’t necessarily have to do something both
times they fire, but they do have the opportunity. Some interceptors only do work
before the action has been executed, and others only do work afterward."
what is meant by they are actually fire after the result? what do we mean by invoking an interceptor
and the firing of an interceptor? Also, if an interceptor is fired only after the result, how is it fired two time
as mentioned in the above paragraph?
Wow. That's an awful explanation of interceptors. Let me try:
Interceptors get piled on the call stack. The pattern of an interceptor looks like so:
Let's say you wanted to hand your actions a database connection. In the "pre action" area, you 'd get a connection from the pool and set it somewhere your action can access it.
The call to invoke either calls the next interceptor or, at the bottom of the interceptor stack, your action. The return value from invoke is the return value from your action.
In the "post action" area, you'd return the connection to the pool.
Does that make any more sense?
I agree--that's a pretty weird explanation, and misleading.
The only thing I'd add to Joe's explanation is that while the result *is* the result of invoking the action, it's also *after* the result has been rendered: personally, I find this a little counter-intuitive, so feel obligated to point it out in case it confuses people like it confuses me :)
Joined: Jun 15, 2010
Can you provide the link to any good book/tutorial on Struts 2..
and can you please define the role of interceptors
Joined: Mar 19, 2008
I found this link very useful in understanding the Struts2 flow.
Struts 2 Flow
I am also new to Struts 2 but I read the flow from this website and Apache's site and tried to draw diagram in paper for better interpretation. It helped me lot. You can also google images for Struts 2 Interceptor Hoping will help you also.......
God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.