<Package name = "defaults" extends = "struts-Default"> <interceptors> <interceptor name = "login" class = "com. zqgame. interceptor. checklogininterceptor "/> <Interceptor-stack name =" myinterceptor "> <Interceptor-ref name =" login "> <Param name =" excludemethods "> validatelogin </param> </interceptor -Ref><Interceptor-ref name = "defaultstack"/></Interceptor-stack> </interceptors> <! -- Set the interceptor stack automatically called by all actions --> <default-interceptor-ref name = "myinterceptor"> </default-interceptor-ref> <global-Results> <result name = "error">/err/exception. JSP </result> <result name = "message">/err/message. JSP </result> </Global-Results> <global-exception-mappings> <exception-mapping exception = "Java. lang. nullpointerexception "result =" error "/> <exception-mapping exception =" Java. lang. exception "result =" error "/> </Global-exception-mappings> </package>
In the action configuration, defaults is inherited:
<package name="login" namespace="/login" extends="defaults"> <action name="login_*" class="loginAction" method="{1}"> </action> </package>
Interceptor class implementation:
Public class checklogininterceptor extends methodfilterinterceptor {private logger log = loggerfactory. getlogger (checklogininterceptor. class); Private Static final long serialversionuid = 1l; @ override protected string dointercept (actioninvocation) throws exception {// check whether a login Map <string, object> session = actioninvocation. getinvocationcontext (). getsession (); string Lo Gin = (string) Session. Get (syskey. login_key); If (LOGIN! = NULL & login. Length ()> 0) {// login is not null, And the logon session is valid. Return actioninvocation. Invoke ();} else {// otherwise, the operation is invalid and login log. debug ("no login, forward login page! "); Return pagecode. login ;}}}