1.概述
Strust攔截器改進(jìn)了Strust對(duì)Action的操作能力,增加了攔截器特性和IoC特性.
通過分析另外的WEB框架,比如:WebWork 2/XWork,Strust攔截器的目的是把其它WEB框架最好的特性整合到STRUTS中.Strust攔截器支持struts1.1, 按照BSD許可發(fā)行.
2.特點(diǎn)
Action 攔截
WW2 操作風(fēng)格
支持 regular 和 Tiles
包括使用Strust攔截器修改過的Strust例子
3.使用方法:
把Strust攔截器配置為一個(gè)struts插件,就可以在需要的任何地方調(diào)用.
4.配置struts插件:
把Strust攔截器配置為一個(gè)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文件中定義了所有攔截(當(dāng)然可以是另外的任何文件名). 這個(gè)文件包含攔截定義和它們應(yīng)該如何被使用.
從兩個(gè)方面來定義 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.