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 閱讀(728) 評論(0)  編輯  收藏 所屬分類: struts

          主站蜘蛛池模板: 建湖县| 峡江县| 始兴县| 潜江市| 普安县| 泸定县| 南岸区| 息烽县| 望江县| 衢州市| 普兰县| 吉林省| 独山县| 嘉鱼县| 桐乡市| 潜江市| 浪卡子县| 彰化市| 弋阳县| 镇安县| 古交市| 吉安县| 信宜市| 广河县| 霍城县| 育儿| 昌黎县| 友谊县| 夏邑县| 东平县| 淳安县| 禹州市| 三明市| 莆田市| 馆陶县| 渭南市| 兖州市| 恭城| 赤壁市| 德惠市| 获嘉县|