actionInvocation.invoke()是什么意思

 

actionInvocation.invoke()是什么意思

标签: interceptorsessionstrutsstringauthenticationuser
  26045人阅读  评论(2)  收藏  举报
  分类:

关于Struts2的自定义的验证截器

[java]  view plain  copy
  1. package ch06.struts2.Interceptor;  
  2.   
  3. import java.util.Map;  
  4.   
  5. import com.opensymphony.xwork2.Action;  
  6. import com.opensymphony.xwork2.ActionInvocation;  
  7. import com.opensymphony.xwork2.interceptor.Interceptor;  
  8.   
  9.   
  10. public class AuthenticationInterceptor implements Interceptor  {  
  11.   
  12.   private static final long serialVersionUID = 1L;  
  13.    
  14.   public static final String USER_SESSION_KEY = "UserSessionKey";  
  15.     
  16.   public void destroy() {}  
  17.   
  18.   public void init() {}  
  19.   
  20.   
  21.      public String intercept(ActionInvocation actionInvocation) throws Exception {  
  22.    //取得Session  
  23.          Map session = actionInvocation.getInvocationContext().getSession();  
  24.    //从Session里获得登录时保存进session的User类  
  25.          String user = (String) session.get(USER_SESSION_KEY);  
  26.          //判断用户名是否为空    
  27.          boolean isAuthenticated = (null!=user);  
  28.          if (!isAuthenticated) {//如果未通过登录验证  
  29.   
  30.            //下面的那个return怎么能返回登录页面  
  31.              return Action.LOGIN;   //返回登录页面    
  32.         
  33.          }else{         
  34.     // 下面的这个actionInvocation.invoke()是什么意思  
  35.          return actionInvocation.invoke();//返回验证通过           
  36.          }  
  37.      }  
  38. }  


struts.xml配置自定义的拦截器

[html]  view plain  copy
  1. <!-- 自定义验证拦截器 -->  
  2.      <interceptors>  
  3.    <interceptor name="Authentication"  class="ch06.struts2.Interceptor.AuthenticationInterceptor" />       
  4.   </interceptors>   
  5.   
  6. <action name="Welcome">  
  7.             <interceptor-ref name ="Authentication"/>  
  8.             <result name="success">welcome.jsp</result>  
  9. </action>  

 

最佳答案
actionInvocation.invoke() 就是通知struts2接着干下面的事情
比如 调用下一个拦截器 或 执行下一个Action
就等于退出了你自己编写的这个interceptor了
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值