<!-- pc用户中心操作,必须登录 --> <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>
拦截器如上
注意Action配置,@ParentPackage需要设置为拦截器的package name或者继承,否则出错
出错信息为:
"Unable to find interceptor class referenced by ref-name XYZ" 因为拦截器convention扫描Action类时,没有Interceptor指定的拦截器。 处理方式为: 1使用@ParentPackage注解(或者指定struts.convention.default.parent.package)指定定义了该Interceptor的package; 2创建一个package并继承定义了该Interceptor的package,同时使用@ParentPackage(或者 struts.convention.default.parent.package)指定该package 下面附运行解决方案:
@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; //查询用户基本信息 @Action(value = "ann_info",interceptorRefs={@InterceptorRef("defaultStacks")}) public String ann_info(){ User users = (User) ActionContext.getContext().getSession().get("user"); System.out.println((null!=users)+"是否存在session"); if(null!=users){ login_user = users; } return "ann_userInfo"; } }