SSH框架搭建

1、新Web工程,并把编码设为utf-8

2,添加框架环境

Junit

Struts2

Hibernate

Spring

3,整合SSH

Struts2与Spring整合

Hibernate与Spring整合

4,资源分类

5,配置日志

    每个框架都需要引用相关的jar包,添加相对应的配置文件。

    整合框架时也需要引用相关的jar包,并完善配置文件。

所有jar包集合


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" />
    <!-- 把扩展名配置为action -->
    <constant name="struts.action.extension" value="action" />
    <!-- 把主题配置为simple -->
    <constant name="struts.ui.theme" value="simple" />
	
    <!--  -->
    <package name="default" namespace="/" extends="struts-default">
      
    </package>

    <!-- Add packages here -->

</struts>

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" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
				http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

	<!-- 自动扫描与装配bean -->
	<context:component-scan base-package="cn.itcast.oa"></context:component-scan>

	
	<!-- 导入外部的properties文件 -->
	<context:property-placeholder location="classpath:jdbc.properties"/>


	<!-- 配置SessionFactory -->
	<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<!-- 指定hibernate的配置文件位置 -->
		<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
		<!-- 配置c3p0数据库连接池 -->
		<property name="dataSource">
			<bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
				<!-- 数据连接信息 -->
				<property name="jdbcUrl" value="${jdbcUrl}"></property>
				<property name="driverClass" value="${driverClass}"></property>
				<property name="user" value="${user}"></property>
				<property name="password" value="${password}"></property>
				<!-- 其他配置 -->
				<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
				<property name="initialPoolSize" value="3"></property>
				<!--连接池中保留的最小连接数。Default: 3 -->
				<property name="minPoolSize" value="3"></property>
				<!--连接池中保留的最大连接数。Default: 15 -->
				<property name="maxPoolSize" value="5"></property>
				<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
				<property name="acquireIncrement" value="3"></property>
				<!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
				<property name="maxStatements" value="8"></property>
				<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
				<property name="maxStatementsPerConnection" value="5"></property>
				<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
				<property name="maxIdleTime" value="1800"></property>
			</bean>
		</property>
	</bean>


	<!-- 配置声明式事务管理(采用注解的方式) -->
	<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>
	<tx:annotation-driven transaction-manager="txManager"/>


</beans>

hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

	<!-- 1,数据库连接信息 -->
	<property name="dialect">
		org.hibernate.dialect.MySQL5InnoDBDialect
	</property>	

	<!-- 2,其他配置 -->
	<property name="show_sql">true</property>
	<property name="hbm2ddl.auto">update</property>

	<!-- 3,导入映射文件 -->
	

</session-factory>

</hibernate-configuration>

jdbc.properties

jdbcUrl		= jdbc:mysql:///itcastoa
driverClass	= com.mysql.jdbc.Driver
user		= ***
password	= ***

log4j.properties

log4j.rootLogger=error, stdout
log4j.logger.cn.itcast.oa=debug

web.xml

<?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">


	<!-- 配置Spring的用于初始化容器对象的监听器 -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext*.xml</param-value>
	</context-param>


	<!-- 配置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>



	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
</web-app>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值