<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)

    好友 小山的博客

    最新隨筆

    最新評論

    主站蜘蛛池模板: eeuss影院ss奇兵免费com| 免费人成视频x8x8入口| 国产在线观a免费观看| 亚洲精品无码你懂的| 亚洲影院在线观看| 亚洲国产精品无码久久一线| 日韩精品成人亚洲专区| AA免费观看的1000部电影| 91香蕉在线观看免费高清| 99视频在线观看免费| 一个人看www免费高清字幕| 色偷偷亚洲第一综合网| 亚洲熟妇无码AV| 亚洲无mate20pro麻豆| 亚洲精品自拍视频| 亚洲宅男永久在线| 亚洲av网址在线观看| 亚洲精品成人无码中文毛片不卡| 亚洲国产成人久久精品99| 免费在线观看亚洲| 免费看少妇作爱视频| 免费看美女让人桶尿口| 黑人粗长大战亚洲女2021国产精品成人免费视频 | 亚洲精品国产首次亮相| 自拍日韩亚洲一区在线| 97久久国产亚洲精品超碰热| 亚洲国产美女在线观看| 亚洲冬月枫中文字幕在线看| 亚洲特级aaaaaa毛片| 亚洲精品成人网站在线播放| 亚洲特级aaaaaa毛片| 亚洲国产精品综合一区在线| 亚洲国产夜色在线观看| 亚洲一级免费视频| 色天使亚洲综合在线观看| 亚洲Av永久无码精品黑人| 在线视频亚洲一区| 菠萝菠萝蜜在线免费视频| 一区二区视频免费观看| a毛看片免费观看视频| 久久午夜无码免费|