You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by PEGASUS84 <pe...@hotmail.it> on 2009/03/15 16:07:53 UTC

interceptor

i've created this interceptor,
does spmeone know why it doesn't work?

package bean;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.opensymphony.xwork2.Action;
import java.util.*;


public class filtro implements Interceptor {
public void destroy() {
}
public void init() {
}
public String intercept( ActionInvocation actionInvocation ) throws
Exception{
Map session = actionInvocation.getInvocationContext().getSession();
utente user = (utente)session.get("autenticato");
if (user != null) {
    System.out.println("condizone if");
return Action.ERROR;
}
else {
    System.out.println("condizione else");
return actionInvocation.invoke();
}
}
}


in document struts.xml there is
 <interceptors>
          <interceptor name="filtro" class="action.bean.filtro"/>
</interceptors>
......
<global result error....



<action ....>

<intercpetor-ref name="filtro">

</action>

-- 
View this message in context: http://www.nabble.com/interceptor-tp22524102p22524102.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: interceptor

Posted by PEGASUS84 <pe...@hotmail.it>.
now it works;
but how can take the message which is in system.out.print...
-- 
View this message in context: http://www.nabble.com/interceptor-tp22524102p22524243.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: interceptor

Posted by Wes Wannemacher <we...@wantii.com>.
On Sunday 15 March 2009 11:07:53 PEGASUS84 wrote:
> i've created this interceptor,
> does spmeone know why it doesn't work?
>
[snip]
>
> <action ....>
>
> <intercpetor-ref name="filtro">
>
> </action>

When you use <interceptor-ref> you are overwriting the current stack with 
whatever you specify. So, this is now the only interceptor that runs on your 
action. I'm guessing that is related to why it doesn't work. Try adding 
another stack like this - 

<action ...>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="filtro" />
</action>

You do have to be aware of a few things when writing interceptors, first off, 
the defaultStack will likely do things during processing that will affect your 
action's processing. If you are looking into the session, make sure that your 
interceptor falls into place in processing where all of your dependencies are 
met. Also, don't put it too late in the stack that your action has already 
been populated and your method called if you are authenticating. If you are 
looking at building an authentication/authorization interceptor stack, check 
out mark menard's tutorial on the subject - 

http://www.vitarara.org/cms/struts_2_cookbook/creating_a_login_interceptor

It is likely exactly what you're looking for.

-Wes

-- 

Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org