<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Spring學(xué)習(xí)筆記系列(四) 與struts整合

    《Spring開發(fā)指南》只寫了一種與struts整合的方法,另一種到Spring2.0 Demo自帶的Doc中查找到Action直接繼承ActionSupport。詳細(xì)信息:

    To integrate your Struts application with Spring, you have two options:

    • Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependencies in a Spring context file.

    • Subclass Spring's ActionSupport classes and grab your Spring-managed beans explicitly using a getWebApplicationContext() method.

    16.3.2. ActionSupport Classes

    As previously mentioned, you can retrieve the WebApplicationContext from the ServletContext using the WebApplicationContextUtils class. An easier way is to extend Spring's Action classes for Struts. For example, instead of subclassing Struts' Action class, you can subclass Spring's ActionSupport class.

    The ActionSupport class provides additional convenience methods, like getWebApplicationContext(). Below is an example of how you might use this in an Action:

    public class UserAction extends DispatchActionSupport {    public ActionForward execute(ActionMapping mapping,                                 ActionForm form,                                 HttpServletRequest request,                                 HttpServletResponse response)            throws Exception {        if (log.isDebugEnabled()) {            log.debug("entering 'delete' method...");        }        WebApplicationContext ctx = getWebApplicationContext();        UserManager mgr = (UserManager) ctx.getBean("userManager");        // talk to manager for business logic        return mapping.findForward("success");    }}

    Spring includes subclasses for all of the standard Struts Actions - the Spring versions merely have Support appended to the name:

    The recommended strategy is to use the approach that best suits your project. Subclassing makes your code more readable, and you know exactly how your dependencies are resolved. However, using the ContextLoaderPlugin allow you to easily add new dependencies in your context XML file. Either way, Spring provides some nice options for integrating the two frameworks.

    可見第二種方法更加簡便。

    JPetstore例子中并沒有使用此方法,而使用了第三種方法。同樣只需要動Action。如下:

    public abstract class BaseAction extends Action {

      private PetStoreFacade petStore;

     public void setServlet(ActionServlet actionServlet) {
      super.setServlet(actionServlet);
      if (actionServlet != null) {
       ServletContext servletContext = actionServlet.getServletContext();
       WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
       this.petStore = (PetStoreFacade) wac.getBean("petStore");
      }
     }

     protected PetStoreFacade getPetStore() {
      return petStore;
     }

    }
    ok,這三種方法都可以讓Spring與Struts整合,相比較第一種(因?yàn)榕渲煤芏噙@里沒寫,見refernce 16.3.1),
    第二第三種方法比較簡潔,侵入不多。

    posted on 2007-06-18 18:00 chenguo 閱讀(192) 評論(0)  編輯  收藏 所屬分類: Spring Dev

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導(dǎo)航

    統(tǒng)計(jì)

    留言簿

    隨筆分類(1)

    文章分類(52)

    好友 小山的博客

    最新隨筆

    最新評論

    主站蜘蛛池模板: 亚洲一区二区三区高清| 国产成人免费手机在线观看视频 | 少妇人妻偷人精品免费视频| 亚洲女人被黑人巨大进入| 免费的黄色的网站| 亚洲欧美国产日韩av野草社区| 日本zzzzwww大片免费| 亚洲国产精品成人久久久| 国产黄色免费网站| 亚洲综合久久一本伊伊区| 成人性生交大片免费看无遮挡| 国内精品久久久久影院亚洲| 日韩免费观看视频| 日本精品久久久久久久久免费| 中文字幕精品亚洲无线码二区 | 亚洲日韩v无码中文字幕| 中文字幕的电影免费网站| 亚洲AV无码专区国产乱码电影| 91香焦国产线观看看免费| 亚洲第一区精品观看| 黄网站免费在线观看| 亚洲视频一区在线| 18禁超污无遮挡无码免费网站 | 特级做a爰片毛片免费看| 国产亚洲av人片在线观看| 国产三级在线免费| 亚洲AV无码久久久久网站蜜桃 | 美丽的姑娘免费观看在线播放| 精品亚洲成A人无码成A在线观看| 国产在线播放免费| 国产一级淫片a免费播放口| 亚洲一级毛片免观看| 亚洲欧洲久久久精品| 18pao国产成视频永久免费| 色偷偷尼玛图亚洲综合| 亚洲gv猛男gv无码男同短文| 国产在线观看片a免费观看| 一级特黄录像视频免费 | 国产亚洲成人在线播放va| 精品久久久久久亚洲综合网| 亚洲熟妇无码另类久久久|