Interceptor class
/** Background Permission check of the interceptor * * For users who have not logged in, can not access*/ Public classPrivilegeinterceptorextendsMethodfilterinterceptor {@Override//How to perform interception protectedString dointercept (actioninvocation actioninvocation)throwsException {//determine if the background user's information is saved in the sessionAdminUser existadminuser= (AdminUser) servletactioncontext.getrequest (). GetSession (). getattribute ("Existadminuser "); if(existadminuser==NULL){ //no login to accessActionsupport actionsupport=(Actionsupport) actioninvocation.getaction (); Actionsupport.addactionerror ("Pro, you have not landed! No access!"); return"Loginfail"; }Else{ //already logged in. returnActioninvocation.invoke (); } }}
Struts
<!--configuring interceptors-<interceptors> <interceptor name= "Privilegeinterceptor"class= "Cn.itcast.shop.interceptor.PrivilegeInterceptor"/> </interceptors> <!--global page-- <global-results> <result name= "Loginfail" >/admin/index.jsp</result> </global-resul ts><!--Configure the background level classification management action--<action name= "admincategory_*"class= "Admincategoryaction" method= "{1}" > <result name= "findAll" >/admin/category/list.jsp</result> <result name= "savesuccess" type= "redirectaction" >adminCategory_findAll.action</result> < ; result name= "deletesuccess" type= "redirectaction" >adminCategory_findAll.action</result> <result na Me= "editsuccess" >/admin/category/edit.jsp</result> <result name= "updatesuccess" type= "Redirectactio N ">adminCategory_findAll.action</result><interceptor-ref name= "Privilegeinterceptor" ></interceptor-ref> <!--Introducing the default interceptor-- <interceptor-ref name= "Defaultstack" ></interceptor-ref></action>
Jsp
Red Code has the effect of real-time refresh, and using interceptors must have it
target= "_parent" name= ' theform ' ></form>
Background permissions check Blocker