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

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

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

    posts - 325,  comments - 25,  trackbacks - 0
     一、spring容器的創(chuàng)建方式
        1.直接在web.xml中配置創(chuàng)建spring容器
            1.1 用ServletContextListener方式實(shí)現(xiàn)
                    <listener>
                        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                    </listener>
                  如果有多個(gè)配置文件需要載入,使用<context-param>元素,ContextLoaderListener加載時(shí),會(huì)查找名為contextConfigLocation的參數(shù),所以,有下面:
                    <context-param>
                            <param-name>contextConfigLocation</param-name>
                            <param-value>/WEB-INF/daoContext.xml,/WEB-INF/applicationContext.xml</param-value>
                    </context-param>
            1.2 用load-on-startup Servlet方式實(shí)現(xiàn)
                    <servlet>
                        <servlet-name>context</servlet-name>
                        <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
                        <load-on-startup>1</load-on-startup>
                    </servlet>
        2.用struts plugin創(chuàng)建spring容器
            在struts-config.xml中加入
            <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
                <set-property property="contextConfigLocation" value="/WEB-INF/action-servlet.xml(用于配置表示層上下文),/WEB-INF/applicationContext.xml"/>
            </plug-in>


    二.問(wèn)題
        如何讓控制器訪問(wèn)到spring容器中的業(yè)務(wù)邏輯組件?有兩種方式2.1,2.2
            2.1 spring管理控制器,并利用IOC為控制器注入邏輯組件
                2.1.1 使用spring的DelegatingRequestProcessor
                            在struts-config.xml中加入
                                <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
                         而后,struts會(huì)接取用戶請(qǐng)求轉(zhuǎn)發(fā)到spring context下的bean,根據(jù)bean的name來(lái)匹配,因此在struts的action中配置type是沒(méi)用的!
                    如下: 
                            <action path="/login" name="loginForm" scope="requerst" validate="true" input="/login.jsp">
                                <forward name="input" path="/login.jsp"/>
                                <forward name="welcom" path="/welcom.jsp"/>
                            </action>
               然后在web.xml中配置:
                <filter>
                        <filter-name>requestContextFilter</filter-name>
                        <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
                </filter>
                <filter-mapping>
                       <filter-name>requestContextFilter</filter-name>
                        <url-pattern>/*</url-pattern>
                </filter-mapping>


               2.1.2   使用DelegatingActionProxy(為了避免應(yīng)用程序本身就擴(kuò)展了RequetstProcessor,DelegatingRequestProcessor就用不成了)
                    DelegatingActionProxy被配置成struts的Action(即所有請(qǐng)求先被ActionServlet得到),轉(zhuǎn)發(fā)到相應(yīng)的Action,而Action的實(shí)現(xiàn)全都是DelegatingActionProxy,DelegatingActionProxy再把請(qǐng)求轉(zhuǎn)發(fā)給spring容器的Action.
                    DelegatingActionProxy不需要在struts-config.xml中配置<controller>元素,只需將action type進(jìn)行如下配置:
                    <action path="/login" name="loginForm" scope="requerst" validate="true" input="/login.jsp" type="org.springframework.web.struts.DelegatingActionProxy">
                                <forward name="input" path="/login.jsp"/>
                                <forward name="welcom" path="/welcom.jsp"/>
                            </action>

          2.2  使用srping的ActionSupport代替struts 的Action
                這種方式下,struts的Action不受spring Ioc容器管理,Action代碼與spring API部分耦合(造成代碼污染),但其增強(qiáng)了代碼的可讀性,Action代碼中顯示調(diào)用業(yè)務(wù)邏輯組件,無(wú)需等容器注入。
                例如:
                public class LoginAction extends ActionSupport {   //繼承spring的ActionSupport         
                       public LoginAction()
                        {
                            //不可在構(gòu)造方法中調(diào)用getWebApplicationContext()
                          } 
                        private LoginService loginService;     //將業(yè)務(wù)邏輯組件對(duì)象作為成員變量
                        public LoginService getLoginService()
                        {
                            return (LoginService)getWebApplicationContext().getBean("loginService");
                        }
                        //重寫execute()方法
                    }
                struts-config.xml中<action>元素正常配置



    http://www.tkk7.com/DenisLing/archive/2005/11/21/20779.html
    posted on 2008-05-12 22:13 長(zhǎng)春語(yǔ)林科技 閱讀(430) 評(píng)論(1)  編輯  收藏 所屬分類: spring

    FeedBack:
    # re: spring 整合struts
    2008-09-22 17:38 | 小小滴
    哥哥,按這樣的配置,還是出現(xiàn)“Servlet action is not available“這個(gè)問(wèn)題,都快郁悶死了,  回復(fù)  更多評(píng)論
      
    <2008年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

     

    長(zhǎng)春語(yǔ)林科技?xì)g迎您!

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊(cè)

    收藏夾

    搜索

    •  

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 野花高清在线观看免费3中文| 在线免费观看污网站| 亚洲国产亚洲片在线观看播放 | 女人让男人免费桶爽30分钟| 免费一级毛suv好看的国产网站 | 中国一级特黄的片子免费 | 亚洲AV成人片色在线观看高潮| 亚洲高清中文字幕免费| 无套内谢孕妇毛片免费看看| 亚洲天天在线日亚洲洲精| 国产男女猛烈无遮挡免费视频网站| 中文字幕免费在线看线人动作大片| 亚洲av一本岛在线播放| 亚洲一区二区三区在线观看精品中文| 男女免费观看在线爽爽爽视频 | 88av免费观看| 一边摸一边爽一边叫床免费视频| 亚洲精品视频久久| 国产成人高清亚洲| 午夜男人一级毛片免费 | 亚洲午夜精品久久久久久浪潮 | 久久青草免费91观看| 国产成人不卡亚洲精品91| 亚洲综合激情视频| 久久精品国产亚洲精品| 在线中文高清资源免费观看| 小日子的在线观看免费| j8又粗又长又硬又爽免费视频| 欧洲 亚洲 国产图片综合| 亚洲va在线va天堂va不卡下载| www.亚洲精品| 免费观看的毛片手机视频| 曰批全过程免费视频播放网站| 一个人看的www免费高清| 亚洲AV无码一区二区乱子仑| 亚洲精品国产情侣av在线| 亚洲国产无套无码av电影| 亚洲国产精品成人AV无码久久综合影院| 插B内射18免费视频| h在线观看视频免费网站| 污视频在线免费观看|