This is an interceptor code for a login to intercept.
I wrote the action into a configuration file, and by comparing the actionname to achieve the interception function
Package Com.shop.web.intercept;import Java.util.arraylist;import Java.util.list;import java.util.ResourceBundle; Import Com.opensymphony.xwork2.action;import Com.opensymphony.xwork2.actioncontext;import Com.opensymphony.xwork2.actioninvocation;import Com.opensymphony.xwork2.actionsupport;import Com.opensymphony.xwork2.interceptor.abstractinterceptor;import Com.shop.web.action.baseaction;public Class Autheninterceptor extends Abstractinterceptor {private list<string> Permissionuris = new arraylist<string> (); @Overridepublic void Init () {ResourceBundle res = Resourcebundle.getbundle ("Permissionuris"); for (String key: Res.keyset ()) {Permissionuris.add (res.getstring (key));} Super.init ();} @Overridepublic string intercept (Actioninvocation invocation) throws Exception {String ActionName = Invocation.getproxy (). Getactionname (); if (Permissionuris.contains (ActionName)) {//If ActionName is in the release list, release return Invocation.invoke ();} Not in the release list verify if you are logged in if (Actioncontext.getcontext (). GetSession (). Get (BaseactIon. Login_user) {==null) {return action.login;//returns the login result}return invocation.invoke ();//Returns the result of the action execution}}
Struts a simple login blocker