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

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

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

    Spring學習筆記系列(四) 與struts整合

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

    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整合,相比較第一種(因為配置很多這里沒寫,見refernce 16.3.1),
    第二第三種方法比較簡潔,侵入不多。

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

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

    導航

    統計

    留言簿

    隨筆分類(1)

    文章分類(52)

    好友 小山的博客

    最新隨筆

    最新評論

    主站蜘蛛池模板: 国产亚洲综合视频| 国产一二三四区乱码免费| 国产一区视频在线免费观看| 无码AV动漫精品一区二区免费| 国产成A人亚洲精V品无码| 成年女人午夜毛片免费看| www永久免费视频| 亚洲一级片在线播放| 亚洲视频一区二区| 嫖丰满老熟妇AAAA片免费看| 有色视频在线观看免费高清在线直播| 亚洲AV日韩AV永久无码免下载| 女人张开腿等男人桶免费视频| 两个人看的www免费视频中文| 中文字幕亚洲码在线| 亚洲色精品88色婷婷七月丁香| 久久精品免费一区二区喷潮 | 亚洲二区在线视频| 亚洲午夜国产片在线观看| 免费看成人AA片无码视频羞羞网| 成人免费网站久久久| 亚洲三级在线观看| 亚洲AV无码国产在丝袜线观看| 国产真人无遮挡作爱免费视频| 免费A级毛片无码专区| 免费夜色污私人影院网站| 91亚洲性爱在线视频| 亚洲一区二区三区偷拍女厕| 欧洲美熟女乱又伦免费视频| 99精品在线免费观看| 国产精品福利片免费看 | 精品一区二区三区无码免费视频| 免费VA在线观看无码| 亚洲精品无码久久久久牙蜜区| 亚洲AV美女一区二区三区| 亚洲精品国精品久久99热| 啦啦啦在线免费视频| 欧洲乱码伦视频免费| 91成人在线免费观看| A级毛片高清免费视频在线播放| 特黄aa级毛片免费视频播放|