ssh全程(Struts+spring+hibernate)
创建一个项目,然后再添加包(显示的页面)和jar包,
然后添加applicationcontext.xml文件里面配置spring,
代码:
<?xmlversion="1.0" encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 配置连接池:-->
<!-- 引入外部属性文件-->
<context:property-placeholderlocation="classpath:jdbc.properties"/>
<!-- 配置C3P0连接池: -->
<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource">
<propertyname="driverClass" value="${jdbc.driver}"/>
<propertyname="jdbcUrl" value="${jdbc.url}"/>
<propertyname="user" value="${jdbc.user}"/>
<propertyname="password" value="${jdbc.password}"/>
</bean>
<!-- Hibernate的相关信息 -->
<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 注入连接池-->
<propertyname="dataSource" ref="dataSource"/>
<!-- 配置Hibernate的其他的属性 -->
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="hibernate.format_sql">true</prop>
<propkey="hibernate.connection.autocommit">false</prop>
<propkey="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 配置Hibernate的映射文件 -->
<propertyname="mappingResources">
<list>
</list>
</property>
</bean>
<!-- 事务管理:-->
<!-- 事务管理器-->
<beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<propertyname="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 开启注解事务-->
<tx:annotation-driventransaction-manager="transactionManager"/>
<!-- Action的配置 ===========================-->
<!-- 首页访问的Action-->
<beanid="indexAction"class="cn.itcast.shop.index.action.IndexAction"scope="prototype">
</bean>
<!-- 用户模块的Action-->
<beanid="userAction"class="cn.itcast.shop.user.action.UserAction"scope="prototype">
</bean>
</beans>
<?xmlversion="1.0" encoding="UTF-8" ?>
<!DOCTYPE strutsPUBLIC
"-//ApacheSoftware Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constantname="struts.devMode" value="false" />
<package name="shop"extends="struts-default" namespace="/">
<!--配置首页访问的Action -->
<!--这里的class连接到是spring配置-->
<actionname="index" class="indexAction">
<resultname="index">/WEB-INF/jsp/index.jsp</result>
</action>
</package>
</struts>
-------------------------------------------------------------------------------------------------
然后添加Struts.xml文件,配置Action,配合spring文件显示界面
代码:
<?xmlversion="1.0" encoding="UTF-8" ?>
<!DOCTYPE strutsPUBLIC
"-//ApacheSoftware Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constantname="struts.devMode" value="false" />
<package name="shop"extends="struts-default" namespace="/">
<!--配置首页访问的Action -->
<!--这里的class连接到是spring配置-->
<actionname="index" class="indexAction">
<resultname="index">/WEB-INF/jsp/index.jsp</result>
</action>
</package>
</struts>