[Java] struts2 action拦截器 →→→→→进入此内容的聊天室

来自 , 2019-09-06, 写在 Java, 查看 104 次.
URL http://www.code666.cn/view/470e7a4f
  1. import org.apache.struts2.ServletActionContext;
  2.  
  3. import com.opensymphony.xwork2.ActionContext;
  4. import com.opensymphony.xwork2.ActionInvocation;
  5. import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
  6.  
  7. public class LoginInterceptor extends AbstractInterceptor {
  8.  
  9.     public String intercept (ActionInvocation invocation) throws Exception {
  10.         String statte = (String) ServletActionContext.getRequest().getSession().getAttribute ("login_state"); //获取登陆状态
  11.         if (statte != null) {  //判断是否为空
  12.             return invocation.invoke();  //如果为是,继续执行ACTION方法
  13.         } else {
  14.             return "backerror";   //如果为否,弹出
  15.         }
  16.     }
  17. }
  18.  
  19.  
  20.  
  21.  
  22. <interceptors>
  23.            <interceptor name="authority" class="org.yzsoft.examdemo.action.LoginInterceptor"></interceptor>
  24.         <!-- 拦截器栈 -->    
  25.            <interceptor-stack name="myDefault">
  26.                <interceptor-ref name="defaultStack"></interceptor-ref>
  27.                <interceptor-ref name="authority"></interceptor-ref>
  28.            </interceptor-stack>
  29.          
  30.        </interceptors>
  31.  
  32.        <global-results>
  33.     <!-- 当返回error视图名时,转入/error.jsp页面 -->    
  34.            <result name="backerror">error.jsp</result>
  35.            <result name="fronterror">login.jsp</result>
  36.        </global-results>

回复 "struts2 action拦截器"

这儿你可以回复上面这条便签

captcha