struts1.1拦截器

 

Usage Notes

To use SAIF, you must configure it as a Struts plugin, configure the interceptor config file, and write any interceptors you need.

Struts Plug-In Configuration

SAIF needs to be configured as a plugin in the Struts configuration file. In the plug-in configuration, the location of the interceptor configuration file needs to be defined. It should look something like this:

<plug-in className="net.sf.struts.saif.SAIFPlugin">
    <set-property property="interceptor-config" value="/WEB-INF/interceptor-config.xml" />
  </plug-in>     

Interceptor Configuration

All interceptors are defined in interceptor-config.xml (of course it could have any name). This file contains the interceptor definitions and how they should be applied. There are two ways to declare interceptors for Struts Actions: globally and by Action. When the Action is requested, first any global interceptors will be applied, then Action-specific interceptors.

The following interceptors are included in SAIF:

Included interceptors
ClassDescription
net.sf.struts.saif.ComponentInterceptor Performs inversion of control functionality. Sets any components the Action has defined it needs.

This is an example of an interceptor configuration file:

<interceptor-config>
<interceptor name="componentInterceptor" type="net.sf.struts.saif.ComponentInterceptor"/>
<interceptor name="testInterceptor" type="net.sf.struts.saif.TestInterceptor"/>

<default-interceptors>
<interceptor name="componentInterceptor"/>
</default-interceptors>

<action type="org.apache.struts.webapp.example.EditRegistrationAction">
<interceptor name="testInterceptor"/>
</action>
</interceptor-config>      

Interceptor Implementation

Interceptors can perform actions before and after a Struts Action is called. To write an interceptor, simple implement the net.sf.struts.saif.ActionInterceptor interface and implement the beforeAction() and afterAction() methods.

This is an example of an interceptor implementation:

public class TestInterceptor implements ActionInterceptor
{
	public void beforeAction(Action action, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	{
		log.debug("beforeAction called");
	}

	public void afterAction(Action action, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	{
		log.debug("afterAction called");
	}

	private Log log = LogFactory.getLog(TestInterceptor.class);
}
          
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值