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

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 连山| 简阳市| 迭部县| 恩平市| 河曲县| 全州县| 康乐县| 元江| 章丘市| 即墨市| 金堂县| 广河县| 刚察县| 布拖县| 县级市| 长宁县| 武隆县| 宁陵县| 宣城市| 青冈县| 武乡县| 怀安县| 贵定县| 鱼台县| 安泽县| 四川省| 固安县| 施甸县| 武宣县| 新河县| 永修县| 榆林市| 杭锦旗| 临清市| 公安县| 上思县| 城口县| 南岸区| 墨玉县| 凤台县| 神农架林区|