您的位置:首页 >> 编程开发 >> Java >> Struts/Hibernate >> 正文
Struts/Hibernate RSS
 

struts拦截器使用

http://www.rdxx.com 08年06月19日 00:00 我要投稿

关键词: 拦截 , Struts

struts拦截器使用

一 方法调用之后使用的拦截器 实现interceptor 接口

拦截器 一定是线程安全的,就是要同步

public interface Interceptor extends Serializable
{
     void destroy();
     void init();
     String intercept(ActionInvocation invocation) throws Exception;
}

实现方法intercept

example

import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class SimpleInterceptor extends AbstractInterceptor
{
     public String intercept(ActionInvocation invocation) throws Exception
{
        MyAction action = (MyAction)invocation.getAction(); 
       action.setDate(new Date()); 
       return invocation.invoke(); 
    }
}

 

<struts>
    ...    <package name="struts-default">
       <interceptors>
          <interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/>
          <interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/>
          ...       </interceptors>
    </package>
    ... </struts>


二  要实现在之前 调用 就实现 PreResultListener的接口


 
 
标签: 拦截 , Struts 打印本文
 
 
  热点搜索
 
 
 


Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站