<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容器的創建方式
        1.直接在web.xml中配置創建spring容器
            1.1 用ServletContextListener方式實現
                    <listener>
                        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                    </listener>
                  如果有多個配置文件需要載入,使用<context-param>元素,ContextLoaderListener加載時,會查找名為contextConfigLocation的參數,所以,有下面:
                    <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方式實現
                    <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創建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>


    二.問題
        如何讓控制器訪問到spring容器中的業務邏輯組件?有兩種方式2.1,2.2
            2.1 spring管理控制器,并利用IOC為控制器注入邏輯組件
                2.1.1 使用spring的DelegatingRequestProcessor
                            在struts-config.xml中加入
                                <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
                         而后,struts會接取用戶請求轉發到spring context下的bean,根據bean的name來匹配,因此在struts的action中配置type是沒用的!
                    如下: 
                            <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(為了避免應用程序本身就擴展了RequetstProcessor,DelegatingRequestProcessor就用不成了)
                    DelegatingActionProxy被配置成struts的Action(即所有請求先被ActionServlet得到),轉發到相應的Action,而Action的實現全都是DelegatingActionProxy,DelegatingActionProxy再把請求轉發給spring容器的Action.
                    DelegatingActionProxy不需要在struts-config.xml中配置<controller>元素,只需將action type進行如下配置:
                    <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部分耦合(造成代碼污染),但其增強了代碼的可讀性,Action代碼中顯示調用業務邏輯組件,無需等容器注入。
                例如:
                public class LoginAction extends ActionSupport {   //繼承spring的ActionSupport         
                       public LoginAction()
                        {
                            //不可在構造方法中調用getWebApplicationContext()
                          } 
                        private LoginService loginService;     //將業務邏輯組件對象作為成員變量
                        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 長春語林科技 閱讀(437) 評論(1)  編輯  收藏 所屬分類: spring

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

     

    長春語林科技歡迎您!

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产va免费观看| 国产精品免费一区二区三区| 四虎国产精品永久免费网址| 伊人婷婷综合缴情亚洲五月| 日韩久久无码免费毛片软件 | 亚洲韩国在线一卡二卡| 国产三级在线免费观看| 国产亚洲人成网站在线观看不卡| 中文在线免费不卡视频| 亚洲成AV人片天堂网无码| 未满十八18禁止免费无码网站 | 亚洲图片校园春色| av无码免费一区二区三区| 亚洲视频一区二区三区四区| 国产精品视频免费一区二区| 噜噜综合亚洲AV中文无码| 日韩精品电影一区亚洲| 成全高清在线观看免费| 亚洲高清美女一区二区三区| 毛片a级毛片免费观看免下载| 欧洲亚洲综合一区二区三区| 亚洲精品动漫人成3d在线| 免费无码一区二区三区蜜桃| 亚洲第一二三四区| 精品少妇人妻AV免费久久洗澡| 麻豆亚洲AV成人无码久久精品| 自拍偷自拍亚洲精品第1页| 无码人妻精品中文字幕免费| 亚洲1234区乱码| 亚洲精品第一国产综合精品99| 国产精品免费大片| 亚洲色大成网站www| 亚洲偷自拍拍综合网| 亚洲一区二区三区免费观看| 亚洲国产成人综合精品| 亚洲人成人无码网www电影首页 | 中文字幕在线免费观看| 亚洲精品天堂无码中文字幕| 日韩精品亚洲aⅴ在线影院| 日本高清在线免费| jizz免费观看视频|