Perhaps your security interceptor could forward to an action, which has the responsibility to handle the error message:
The interceptor: public String intercept(ActionInvocation actionInvocation) throws Exception { Map session = actionInvocation.getInvocationContext().getSession(); User user = (User) session.get(Constants.USER_KEY); boolean isAuthenticated = (null != user); if (isAuthenticated) { return actionInvocation.invoke(); } else { return "needAuthentication"; } The global results: <result name="needLogin" type="redirect-action"> <param name="actionName">login_violation</param> <param name="namespace">/</param> </result> And in your action (the login action, which gathers all login stuff): @SkipValidation public String violation() { addActionMessage(getText("need.authentication")); return SUCCESS; // to the login form } Worked for me. Cheers, Arnaud -----Message d'origine----- De : M.Liang Liu [mailto:[EMAIL PROTECTED] Envoyé : mercredi 18 juillet 2007 10:59 À : Struts Users Mailing List Objet : Re: How can I add ActionErrors when do the interceptor's intercept() method? I tried many times,but there's no solutions then. Any help could be greatly appreciated. On 7/17/07, M.Liang Liu <[EMAIL PROTECTED]> wrote: > > Thanks for you quick reply,Nuwan. > > yeah,ur code works and action-error should be add to the original action(I > tested). > However,I set my global result in my default package,and when the invalid > action accessing was intercepted,the browser was redirect to the login page. > > It's strange that the action-error did NOT display.I am sure that my > interceptor has been configured correctly and the actionError has been add > to the very action. > I guess the global result whose type is "redirect" cause this problem,but > am not sure. > > So,I define my login result as dispatch,which is default, it works.Myglobal result is follwing: > > ---------------------------------------------------------------------------- ---- > <global-results> > <result name="error">/error.jsp</result> > <result name="login">/common/login.jsp</result> > <result name="invalid.token">/error.jsp</result> > </global-results> > > ---------------------------------------------------------------------------- ------ > > Does it work?yes.action error has been add and can display correctly. > The problem is that I can NOT use redirect type any more.As a result,the > doLogin action---the login form's action---can not mapped,as the namespace > now is still the invalid action's. > eg.I access :http://localhost:8080/myapp/kms/showNews.tbs before logged in > Then access was intercepted and dispatched to : > http://localhost:8080/myapp/common/login.jsp > so I logged. > The form was submitted to http://localhost:8080/myapp/kms/doLogin.tbs > which should be: http://localhost:8080/myapp/common/doLogin.tbs > > Any comment? > > Thanks a lot. > On 7/18/07, Nuwan Chandrasoma <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > hope this code will help you. > > > > Object action = invocation.getAction (); > > if (action instanceof com.opensymphony.xwork2.ValidationAware) { > > ((com.opensymphony.xwork2.ValidationAware) action).addActionError > > ("Username or password incorrect."); > > } > > > > Thanks, > > > > Nuwan. > > > > ----- Original Message ----- > > From: "M.Liang Liu" <[EMAIL PROTECTED] > > > To: <user@struts.apache.org> > > Sent: Tuesday, July 17, 2007 9:49 AM > > Subject: How can I add ActionErrors when do the interceptor's > > intercept() > > method? > > > > > > > > > > Hi,all > > > I've got a problem when I put my own interceptors in my app: > > > I write an interceptor to authenticate whether the user access the > > current > > > page or action has logged in. > > > I write the code in the following style(refer to the mailreader > > example): > > > -------------------------------------------------------------------- > > > ...... > > > public String intercept(ActionInvocation actionInvocation) throws > > > Exception > > > { > > > Map session = actionInvocation.getInvocationContext().getSession(); > > > User user = (User) session.get(Constants.USER_KEY); > > > boolean isAuthenticated = (null != user); > > > if (isAuthenticated) { > > > return actionInvocation.invoke(); > > > } else { > > > //how to add actionErrors here? > > > return Action.LOGIN; > > > } > > > ..... > > > > > > -------------------------------------------------------------------- > > > The question is that :how can I addActionErrors to the interceptor,so > > that > > > when the invalid action---namelly not logged in---was redirected to > > the > > > login page,some actionErrors messages like "You are not logged in" can > > > > > display. > > > > > > I notice that I can put cite addActionErrors("You are not logged in"); > > in > > > my > > > action class,however,I do NOT have any hint how to add action errors > > in my > > > interceptor. > > > Just or can't? > > > > > > Any comment would be appreciated. > > > -- > > > View this message in context: > > > > > http://www.nabble.com/How-can-I-add-ActionErrors-when-do-the-interceptor%27s -intercept%28%29-method--tf4095868.html#a11646263 > > > Sent from the Struts - User mailing list archive at Nabble.com . > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > -- > ------M.Liang Liu -- ------M.Liang Liu --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]