Spring學習雜記一

          0, Spring本身的一些工作(比如,根上下文的建立)可以在ContextLoaderServlet或ContextLoaderListener中完成;
          1, 如果需要使用Spring MVC就需要引入DispatcherServlet,否則可以不用引入這個servlet,
          而引入其他的servlet(比如,如果webApplication需要使用struts MVC,就需要引入struts的servlet,如ActionServlet).
          2, Spring與Struts的結合:
          ??方法一:
          ????a. 利用Spring的ContextLoaderServlet或ContextLoaderListener加載Spring所需要的Bean定義及ApplicationContext的建立等;
          ????b. 定義Struts所需要的Dispatcher類ActionServlet,其中a,b兩步是獨立的;
          ????c. 在Struts的action中引用Spring中的bean定義時,可以直接使用WebApplicationContextUtil
          ????
          ????如: a. web.xml的配置:
          ??????<context-param>
          ???????<param-name>contextConfigLocation</param-name>
          ???????<param-value>/WEB-INF/beanDefineA.xml</param-value>
          ??????</context-param>
          ??????
          ??????<servlet>
          ???????<servlet-name>ContextLoader</servlet-name>
          ???????<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
          ???????<load-on-startup>1</load-on-startup>
          ??????</servlet>
          ??????<servlet>
          ????????? <servlet-name>action</servlet-name>
          ????????? <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
          ????????? <init-param>
          ??????????? <param-name>config</param-name>
          ??????????? <param-value>/WEB-INF/struts-config.xml</param-value>
          ????????? </init-param>
          ????????? <load-on-startup>2</load-on-startup>
          ??????? </servlet>
          ??????
          ??????<servlet-mapping>
          ???????<servlet-name>ContextLoader</servlet-name>
          ???????<url-pattern>/</url-pattern>
          ??????</servlet-mapping>
          ??????<servlet-mapping>
          ???????<servlet-name>action</servlet-name>
          ???????<url-pattern>*.do</url-pattern>
          ??????</servlet-mapping>
          ??????
          ??????b. bean定義文件內容如下:
          ???????<bean id="test" class="com.info.test">
          ?????? ??<property name="id">
          ?????? ???<value>1</value>
          ?????? ??</property>
          ?????? ??<property name="name">
          ?????????<value>zqbchina</value>
          ????????</property>
          ?????? ??<property name="age">
          ?????????<value>12</value>
          ????????</property>
          ?????? ?</bean>
          ?????? ?
          ?????? c. action中的引用:
          ?????? ...
          ?????? ServletContext sc = request.getSession().getServletContext();
          ??????WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc);
          ??????test t = (test)wac.getBean("test");
          ??????...

          posted on 2007-11-27 17:31 心硯 閱讀(354) 評論(0)  編輯  收藏 所屬分類: Java

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          文章分類

          文章檔案

          Forum

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 建瓯市| 郸城县| 方正县| 米脂县| 吉隆县| 连云港市| 哈巴河县| 呈贡县| 清原| 江西省| 万源市| 留坝县| 通州区| 乌海市| 多伦县| 呼和浩特市| 宁远县| 江口县| 保德县| 尉氏县| 涞水县| 漳浦县| 内乡县| 阳信县| 武汉市| 舒城县| 洞头县| 民和| 博湖县| 南召县| 台湾省| 太和县| 凤山市| 芜湖市| 马龙县| 宁强县| 高台县| 昌平区| 寿阳县| 内丘县| 瓦房店市|