struts2: Redirect from global interceptor
Posted
by Dewfy
on Stack Overflow
See other posts from Stack Overflow
or by Dewfy
Published on 2010-04-23T16:10:38Z
Indexed on
2010/04/23
16:13 UTC
Read the original article
Hit count: 460
In struts2 I have very simple task, after user is logged-in I'm checking if they profile is complete. If not user should be blocked from any other action and redirected to edit page. So I have created my default package:
<package name="main" extends="tiles-default" >
<interceptors>
<interceptor name="checkProfile" class="my.CheckProfileInterceptor" />
<interceptor-stack name="secure">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="checkProfile"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secure"/>
</package>
After it all my packages would include this template as a base:
<package namespace="/packageA" name="packageA" extends="main">
...
<package namespace="/packageB" name="packageB" extends="main">
...
Saying editing page is /packageA/editProfile, my interceptor does following:
public String intercept(ActionInvocation actionInvocation) throws Exception
{
if( currentUser.isOk() )
return "editProfile";
...
BUT! interceptor is global, so it raises struts2 error:
No result defined for action (name of editProfile action class)
When interceptor is placed inside some package - then everything ok. What should i do to declare global action?
© Stack Overflow or respective owner