国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Spring與Struts2集成開發

2019-11-15 01:08:43
字體:
來源:轉載
供稿:網友
SPRing與Struts2集成開發
Struts2和Spring都是不錯的開源框架,Spring與Struts2集成開發,把二者結合在一起使用,開發效果更佳,效率杠杠的。下面介紹一下如何將Spring與Struts2集成在一起開發。分七步戰略:
1、添加Struts2 支持jar包  ;注意:加上一個Struts-spring-plugin(集成)插件包2、添加spring 支持jar包3、編寫struts.xml配置文件注意:Action是交由Spring管理;所以action class屬性應和spring 中配置的Action  Bean ID一致
<!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"    "http://struts.apache.org/dtds/struts-2.3.dtd">    <struts>        <package name="default" namespace="/" extends="struts-default">            <!-- 配置用戶ACTION                 Action由Spring維護                class就是spring中Action  Bean的ID            -->            <action name="useraction*" class="useraction" method="{1}">                <result name="success" type="redirect">success.jsp</result>                <result name="login" type="redirect">index.jsp</result>            </action>                    </package>    </struts>

4、在web.xml中配置struts2過濾器
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5"     xmlns="http://java.sun.com/xml/ns/javaee"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">    <!-- 配置struts2核心過濾器 -->    <filter>        <filter-name>Struts2</filter-name>        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>    </filter>    <filter-mapping>        <filter-name>Struts2</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>        <!-- 指定spring配置文件所在位置 -->    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath:applicationContext.xml</param-value>    </context-param>    <!-- 配置sprig監聽器 -->    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>        <welcome-file-list>      <welcome-file>index.jsp</welcome-file>    </welcome-file-list></web-app>

5、編寫spring配置文件applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="http://www.springframework.org/schema/beans           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">        <!-- 配置持久化層 new userdao()-->    <bean id="userdao" class="DAO.impl.UserDaoimpl" scope="prototype"></bean>        <!-- 創建業務層 new userbiz() -->      <bean id="userbiz" class="BIZ.impl.UserBizimpl" scope="prototype">          <!-- 注入持久化層 DAO              IUuserDao userdao = new userdao()          -->          <property name="userdao" ref="userdao"></property>      </bean>            <bean id="useraction" class="Action.UserAction" scope="prototype">          <!-- 注入業務層BIZ               IUserBiz userbiz = new UserBiz()          -->          <property name="userbiz" ref="userbiz"></property>      </bean></beans>

6、在web.xml中配置spring監聽器和指定配置文件所在位置(注:如果其文件在WEB-INF/applicatonContext.xml下的話就不需要指定)
        <!-- 指定spring配置文件所在位置 -->    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath:applicationContext.xml</param-value>    </context-param>    <!-- 配置sprig監聽器 -->    <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>

7、編寫三層結構;通過spring依次注入各依賴對象BIZ 中注入 DAO層Action 層中注入  BIZ層

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洛川县| 尉犁县| 西畴县| 琼海市| 宝兴县| 闸北区| 新化县| 和平区| 莲花县| 平顺县| 湘潭市| 林西县| 洮南市| 二连浩特市| 衡阳县| 焦作市| 阿巴嘎旗| 赫章县| 阿克苏市| 子洲县| 宁都县| 子长县| 建湖县| 且末县| 象山县| 乌恰县| 延寿县| 阿克苏市| 桂东县| 汤阴县| 江孜县| 静宁县| 和顺县| 科技| 甘谷县| 平舆县| 陇南市| 石城县| 宜都市| 高平市| 鲁山县|