<!-- pc User Center operation, must be logged in --><package name= "User_login" namespace= "/" extends = "Json-default,struts-default" ><interceptors> <interceptor name= "ress" class= "Com.common.interceptor.ErrorInterceptor" /> <interceptor name= " Userislogin " class=" Com.common.interceptor.Check_P_UserIsLogin " /> < Interceptor-stack name= "Defaultstacks" ><interceptor-ref name= "ress" ></interceptor-ref ><interceptor-ref name= "Userislogin" ></interceptor-ref><interceptor-ref name= " Defaultstack "></interceptor-ref> </interceptor-stack> </interceptors> <global-results><result name= "PloginUI" >/ Web-inf/jsp/pc/login.jsp</result><result name= "Error" >/WEB-INF/jsp/pc/404.jsp</result> <result name= "Input" >/web-inf/jsp/pc/404.jsp</result></global-results> </package>
Interceptor above
Note that the action configuration, @ParentPackage need to be set to the Interceptor's package name or inheritance, or an error
The error message is:
"Unable to find interceptor class referenced by Ref-name XYZ" because the Interceptor Convention scan the action class, there is no interceptor specified interceptor. Handled by: 1 use @parentpackage annotations (or specify struts.convention.default.parent.package) to specify the package that defines the interceptor; 2 Create a package and inherit the package that defines the interceptor, using @parentpackage (or struts.convention.default.parent.package) Specify the package to run the solution under:
@Controller @scope ("prototype") @Namespace ("") @ParentPackage ("User_login") @Results (value={@Result (name = "Ann_json", type = "json", params={"root", "Jsonmap"}), @Result (name = "Ann_user", location = "/web-inf/jsp/pc/user/user.jsp"), @Result (name = "Ann_userinfo", location = "/web-inf/jsp/pc/user/info.jsp"), @Result (name = "Ann_registererror",location = "/ Web-inf/jsp/pc/register.jsp "), @Result (name = " Ann_login " ,location="/web-inf/jsp/pc/login.jsp ") }) public class puseraction extends baseaction<user> {private static final long serialversionuid = 2324932911275746283l;//Query user basic information @action (value = " Ann_info ", interceptorrefs={@InterceptorRef (" Defaultstacks ")}) Public string ann_info () {user users = (user) actioncontext.getcontext (). GetSession (). Get ("user"); System.out.println ((null!=users) + "existence session"); if (null!=users) {login_user = users;} return "Ann_userinfo";}}
This article is from the "Green Years" blog, be sure to keep this source http://alex233.blog.51cto.com/8904951/1763867
STRUTS2 annotations using interceptors interceptor and Interceptor-stack