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

          主站蜘蛛池模板: 贺兰县| 临江市| 东宁县| 遂溪县| 孝昌县| 泰兴市| 绥阳县| 朝阳县| 阜康市| 桑植县| 三明市| 神农架林区| 兴城市| 浦县| 阳春市| 兰坪| 保康县| 荣成市| 天柱县| 汕头市| 靖西县| 宜阳县| 延津县| 泰兴市| 梨树县| 太谷县| 江门市| 常州市| 杭锦旗| 延长县| 花垣县| 盘锦市| 沙坪坝区| 赣州市| 雷山县| 崇礼县| 公安县| 乐东| 乳源| 西盟| 昔阳县|