一、首先在WebContent/WEB-INF/路径下创建web.xml文件,创建把权利转交给spring和struts文件。
Web.xml
<!-- 表示头文件 -->
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>SSHTest</display-name>
<!-- struts Framework -->
<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 Framework -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- welcome file -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
二、其次在WebContent/WEB-INF/路径下创建applicationContext.xml这是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" 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-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!-- sessionFactory -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:orcl">
</property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
<!-- 数据工厂类 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle10gDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/myssh/bean/Test.hbm.xml</value>
</list>
</property>
</bean>
<!-- 登陆的action的实现类 -->
<bean id="loginaction" class="com.myssh.action.LoginAction">
<property name="userservice" ref="loginservice"></property>
</bean>
</beans>
三、其次在src文件下创建struts.xml,这是struts标签的创建,为action服务的一个配置文件。
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>
<!-- 定义struts.objectFactory常量,由Spring框架来生成相应的对象 (必须写)-->
<constant name="struts.objectFactory" value="spring"></constant>
......
</struts>
四、在你要进行数据连接的类(bean)文件里,配置hibernate的文件Test.hbm.xml
Test.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.myssh.bean" >
<class name="Test" table="test" schema="scott">
<id name="id" column="id" type="int" >
<generator class="sequence">
<param name="sequence">idsquen</param>
</generator>
</id>
<property name="name" column="name" type="string"></property>
<property name="age" column="age" type="int"></property>
<property name="info" column="info" type="string"></property>
</class>
</hibernate-mapping>
注意:主键一定要写,还有映射关系一定要知道,不然开发很难
五、就是在lib文件下添加需要的包(以上配置文件针对于oracle数据库)

