ssh框架搭建

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 19
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值