SSH整合(struts2)

 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	
	<!-- spring的上下文环境监听器 -->
	<context-param>      
	    <param-name>contextConfigLocation</param-name>      
	    <param-value>/WEB-INF/applicationContext.xml</param-value>      
	 </context-param> 
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<!-- struts的过滤器 -->
	<filter>    
        <filter-name>ssh</filter-name>    
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class >    
    </filter>    
    <filter-mapping>    
        <filter-name>ssh</filter-name>    
        <url-pattern>/*</url-pattern>    
    </filter-mapping>    
 	<welcome-file-list>
    	<welcome-file>index.jsp</welcome-file>
  	</welcome-file-list>
</web-app>

 application.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.0.xsd">
	
	<!-- //////////////////////////SSH整合/////////////////////////// -->
	<!-- spring和hirbnate整合:配置sessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
	</bean>
	<!-- spring和hirbnate整合:配置事务管理器 -->
	<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<!-- spring和hirnaate整合:配置事务拦截器 -->
	<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<!-- TransactionInterceptor的父类有transactionManager和transactionAttributes(set方法) -->
		<property name="transactionManager" ref="transactionManager"></property>
		<property name="transactionAttributes">
			<props>
				<prop key="store*">PROPAGATION_REQUIRED</prop>
				<prop key="delete*">PROPAGATION_REQUIRED</prop>
				<prop key="update*">PROPAGATION_REQUIRED</prop>
				<prop key="confirm*">PROPAGATION_REQUIRED</prop>
				<prop key="get*">readOnly</prop>
				<prop key="load*">readOnly</prop>
				<prop key="find*">readOnly</prop>
			</props>
		</property>
	</bean>
	<!-- spring配置自动代理(注入beansNames和interceptorNames(String[]数组,在父类中) -->
	<bean id="autoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<!-- 根据bean的名字区配-->
		<property name="beanNames" value="*Service"></property>
		<property name="interceptorNames" value="transactionInterceptor"></property>
	</bean>

	<!-- ////////////////////////////Dao和Service Bean////////////////////////////// -->
	<bean id="supplierDao" class="com.aowin.dao.impl.SupplierDaoImpl" scope="singleton">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="supplierService" class="com.aowin.service.impl.SupplierServiceImpl" scope="singleton">
		<property name="supplierDao" ref="supplierDao"></property>
	</bean>
	
	<bean id="purchDao" class="com.aowin.dao.impl.PurchDaoImpl" scope="singleton">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="purchService" class="com.aowin.service.impl.PurchServiceImpl" scope="singleton">
		<property name="purchDao" ref="purchDao"></property>
	</bean>
	
	<bean id="bicyDao" class="com.aowin.dao.impl.BicyDaoImpl" scope="singleton">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="bicyService" class="com.aowin.service.impl.BicyServiceImpl" scope="singleton">
		<property name="bicyDao" ref="bicyDao"></property>
	</bean>
	
	<bean id="stopDao" class="com.aowin.dao.impl.StopDaoImpl" scope="singleton">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="stopService" class="com.aowin.service.impl.StopServiceImpl" scope="singleton">
		<property name="stopDao" ref="stopDao"></property>
	</bean>
	
	<bean id="stackDao" class="com.aowin.dao.impl.StackDaoImpl" scope="singleton">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<bean id="stackService" class="com.aowin.service.impl.StackServiceImpl" scope="singleton">
		<property name="stackDao" ref="stackDao"></property>
	</bean>
	
	<!-- ////////////////////////////Action Bean/////////////////////////////////// -->
	<bean id="supplierUIAction" class="com.aowin.action.SupplierUIAction" scope="prototype">
		<property name="supplierService" ref="supplierService"></property>
	</bean>
	
	<bean id="supplierBatchDelAction" class="com.aowin.action.SupplierBatchDelAction" scope="prototype">
		<property name="supplierService" ref="supplierService"></property>
	</bean>
	
	<bean id="supplierStoreAction" class="com.aowin.action.SupplierStoreAction" scope="prototype">
		<property name="supplierService" ref="supplierService"></property>
	</bean>
	
	<bean id="purchUIAction" class="com.aowin.action.PurchUIAction" scope="prototype">
		<property name="purchService" ref="purchService"></property>
		<property name="supplierService" ref="supplierService"></property>
	</bean>
	
	<bean id="purchStoreAction" class="com.aowin.action.PurchStoreAction" scope="prototype">
		<property name="supplierService" ref="supplierService"></property>
		<property name="purchService" ref="purchService"></property>
	</bean>
	
	<bean id="stopMainAction" class="com.aowin.action.StopMainAction" scope="prototype">
		<property name="stackService" ref="stackService"></property>
		<property name="stopService" ref="stopService"></property>
		<property name="bicyService" ref="bicyService"></property>
	</bean>
	
	<bean id="setStakeAction" class="com.aowin.action.SetStakeAction" scope="prototype">
		<property name="stopService" ref="stopService"></property>
		<property name="stackService" ref="stackService"></property>
		<property name="bicyService" ref="bicyService"></property>
	</bean>
	<bean id="atteAction" class="com.aowin.action.AtteAction" scope="prototype">
		<property name="bicyService" ref="bicyService"></property>
	</bean>
</beans>

 struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<constant name="struts.devMode" value="true" />
	<constant name="struts.ui.theme" value="simple"></constant>
	<!--  Spring和Struts的整合:指定对象的创建由spring管理 -->
	<constant name="struts.objectFactory" value="spring"></constant>
	
	<include file="struts-purch.xml"></include>
	<include file="struts-supplier.xml"></include>
	<include file="struts-stop.xml"></include>
</struts>

struts-supplier.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
		
	<package name="supplier" namespace="/supplier"
		extends="struts-default">
		<global-results>
			<result name="message">/message</result>
		</global-results>
		
		<action name="main" class="supplierUIAction" method="main">
			<result name="success">/WEB-INF/page/supplier/suppliermain.jsp</result>
		</action>
		<action name="add" class="supplierUIAction" method="add">
			<result name="success">/WEB-INF/page/supplier/supplieradd.jsp</result>
		</action>
		<action name="update" class="supplierUIAction" method="update">
			<result name="success">/WEB-INF/page/supplier/supplierupdate.jsp</result>
			<result name="error" type="redirectAction">main</result>
		</action>

		<action name="batchdel" class="supplierBatchDelAction">
			<result type="redirectAction">main</result>
		</action>
	</package>
	
	<package name="supplierstore" namespace="/supplierstore"
		extends="struts-default">
		<global-results>
			<result name="message">/message</result>
		</global-results>
		<action name="storeadd" class="supplierStoreAction" method="add">
			<result name="input">/WEB-INF/page/supplier/supplieradd.jsp</result>
			<result name="success" type="redirectAction">
				<param name="namespace">/supplier</param>
				<param name="actionName">main</param>
			</result>
		</action>
		
		<action name="storeupdate" class="supplierStoreAction" method="add">
			<result name="input">/WEB-INF/page/supplier/supplierupdate.jsp</result>
			<result name="success" type="redirectAction">
				<param name="namespace">/supplier</param>
				<param name="actionName">main</param>
			</result>
		</action>
	</package>
	
</struts>

猜你喜欢

转载自88548886.iteye.com/blog/1534993