posts - 119, comments - 62, trackbacks - 0, articles - 0
          開發環境:
          window xp
          jdk 1.5
          tomcat 5.028
          eclispe 3.2
          myeclipse 4.0
          步驟:
          (1)新建一個web project,名稱為suzhouadmin
          (2)在項目上點鼠標右鍵,選擇myeclipse->add spring capablities...
          (3)把Spring 1.2 AOP,Spring 1.2 Core Lib,Spring ORM/DAO/Hibernate 3.0 lib,Spring 1.2 web lib選擇中,Copy Checked lib content to project folder,然后點Next
          (4)folder改為:WebRoot/WEB-INF,File為applicationContext.xml不變。點Finish。
          Spring的引用完成。

          (5)在項目上點鼠標右鍵,選擇myeclipse->add Struts capablities...
          (6)選擇struts1.1,base package for classes?改成 com.suzhou.admin.struts,然后點finish。

          Struts的引用完成。
          (6)新建立一個包com.suzhou.admin.hibernate,然后在項目上點鼠標右鍵,選擇myeclipse->add Hibernate capablities...
          (7)把Hibernate 3.0 core lib,Hibernate 3.0 advanced lib中,Copy Checked lib content to project folder,點Next
          (8)選擇Spring Configuration file(applicationContext.xml),點Next
          (9)選擇Exit spring configuration file.輸入sessionFactory id為sessionFactory。點Next
          (10)設置數據源ID為dataSource,選擇一個已經設置好的DB profile,然后點Next
          (11)點Package...選擇com.suzhou.admin.hibernate,自動生成類名com.suzhou.admin.hibernate.HibernateSessionFactory。

          開始配置Struts和Spring.
          (12)打開WEB-INFO/web.xml,在最后面添加:
          ?<servlet>
          ??<servlet-name>context</servlet-name>
          ??<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
          ??<load-on-startup>1</load-on-startup>
          ?</servlet>
          這樣,Spring 的ApplicationContext就配置好了。通過以上配置,Web容器會自動加載/WEB-INF/applicationContext.xml初始化
          ApplicationContext實例,如果需要指定配置文件位置,可通過context-param加以指定:
          <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/myApplicationContext.xml</param-value>
          </context-param>
          配置完成之后,即可通過
          WebApplicationContextUtils.getWebApplicationContext()
          方法在Web應用中獲取ApplicationContext引用。

          (13)通過Struts config新建一個Action名為LoginAction,自動生成的action定義如下:
          ??? <action
          ????? attribute="loginForm"
          ????? input="/index.jsp"
          ????? name="loginForm"
          ????? path="/login"
          ????? scope="request"
          ????? type="com.suzhou.admin.struts.action.LoginAction">
          ????? <forward name="loginfail" path="/error.jsp" />
          ????? <forward name="loginok" path="/main.jsp" />
          ??? </action>
          把其改成:
          ??? <action
          ????? attribute="loginForm"
          ????? input="/index.jsp"
          ????? name="loginForm"
          ????? path="/login"
          ????? scope="request"
          ????? type="org.springframework.web.struts.DelegatingActionProxy">
          ????? <forward name="loginfail" path="/error.jsp" />
          ????? <forward name="loginok" path="/main.jsp" />
          ??? </action>
          并在struts-config.xml中添加Spring插件。
          ?<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
          ??<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
          ?</plug-in>
          (13)用Myeclipse Spring donfig editor打開applicationContext.xml,點右鍵,選擇new Bean,輸入Bean name為/login,calss為com.suzhou.admin.struts.action.LoginAction。點finish,applicationContext.xml多加了一個Bean定義:
          <bean name="/login" class="com.suzhou.admin.struts.action.LoginAction" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default"></bean>

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 卢湾区| 固始县| 定南县| 北宁市| 醴陵市| 彰化市| 金坛市| 清徐县| 故城县| 清流县| 青海省| 靖西县| 桐庐县| 隆林| 岢岚县| 台北市| 金堂县| 永泰县| 同心县| 抚顺市| 廉江市| 来安县| 福泉市| 新巴尔虎右旗| 邵东县| 麦盖提县| 汝南县| 裕民县| 永年县| 阜南县| 缙云县| 富民县| 莫力| 交口县| 朝阳县| 磐石市| 宁夏| 包头市| 德惠市| 阿克苏市| 博罗县|