Junky's IT Notebook

统计

留言簿(8)

积分与排名

WebSphere Studio

阅读排行榜

评论排行榜

Strust拦截器

1.概述

Strust拦截器改进了Strust对Action的操作能力,增加了拦截器特性和IoC特性.

通过分析另外的WEB框架,比如:WebWork 2/XWork,Strust拦截器的目的是把其它WEB框架最好的特性整合到STRUTS中.Strust拦截器支持struts1.1, 按照BSD许可发行.

2.特点
Action 拦截
WW2 操作风格
支持 regular 和 Tiles
包括使用Strust拦截器修改过的Strust例子


3.使用方法:

把Strust拦截器配置为一个struts插件,就可以在需要的任何地方调用.


4.配置struts插件:

把Strust拦截器配置为一个struts插件,只需要修改 Struts 配置文件就可以了,修改后的配置文件.一般看起来像这种样子:

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


5.拦截器的配置

在interceptor-config.xml文件中定义了所有拦截(当然可以是另外的任何文件名). 这个文件包含拦截定义和它们应该如何被使用.

从两个方面来定义 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 Class Description
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);
}
Contact
Please contact Lars Hoss or Don Brown with comments, bug reports, and suggestions.

posted on 2007-06-28 09:35 junky 阅读(719) 评论(0)  编辑  收藏 所属分类: struts


只有注册用户登录后才能发表评论。


网站导航: