三大框架配制(eclispe)

      在SSH中spring起着整合的作用,所以在这里,我重点讲一下spring的配制。

      一、引用相关包,并配制

      

 1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
3 "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
4 <beans>
5 <!-- 配置数据源 -->
6 <bean id="dataSource"
7 class="org.apache.commons.dbcp.BasicDataSource"
8 destroy-method="close">
9 <property name="driverClassName">
10 <value>com.mysql.jdbc.Driver</value>
11 </property>
12 <property name="url">
13 <value>jdbc:mysql://localhost:3306/demo?useUnicode=true&amp;characterEncoding=utf-8</value>
14 </property>
15 <property name="username">
16 <value>root</value>
17 </property>
18 <property name="password">
19 <value>123456</value>
20 </property>
21 </bean>
22 <!-- 配置Hibernate -->
23 <bean id="sessionFactory"
24 class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
25 <property name="dataSource">
26 <ref local="dataSource" />
27 </property>
28 <property name="mappingResources">
29 <list>
30 <value>com/model/User.hbm.xml</value>
31 <value>com/model/Address.hbm.xml</value>
32 </list>
33 </property>
34 <property name="hibernateProperties">
35 <props>
36 <prop key="hibernate.dialect">
37 org.hibernate.dialect.MySQLDialect
38 </prop>
39 <prop key="hibernate.show_sql">true</prop>
40 </props>
41 </property>
42 </bean>
43 <!-- 配置事务 -->
44 <bean id="transactionManager"
45 class="org.springframework.orm.hibernate3.HibernateTransactionManager">
46 <property name="sessionFactory">
47 <ref local="sessionFactory" />
48 </property>
49 </bean>
50
51 <!-- DAO -->
52 <bean id="User_Dao" class="com.dao.User_Dao">
53 <property name="sessionFactory">
54 <ref local="sessionFactory" />
55 </property>
56 </bean>
57
58
59 <!-- 定义DAO代理 -->
60 <bean id="UserDAOProxy"
61 class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
62 <property name="transactionManager">
63 <ref bean="transactionManager" />
64 </property>
65 <property name="target">
66 <ref local="User_Dao" />
67 </property>
68 <property name="transactionAttributes">
69 <props>
70 <prop key="insert*">PROPAGATION_REQUIRED</prop>
71 <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
72 </props>
73 </property>
74 </bean>
75 <!-- Action -->
76 <bean id="User_Action" class="com.action.User_Action">
77 <property name="user_dao">
78 <ref local="User_Dao" />
79 </property>
80 </bean>
81 </beans>

  1.datasource数据源配制

  2.配制hibernate   sessionfactory工厂的创建

  3.配制事务操作

  4.写一个DAO和一个DAO代理

  5.写一个Action代理

二、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:jsp="http://java.sun.com/xml/ns/javaee/jsp" 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>demo</display-name>
<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>
<filter>
<filter-name>struts</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

1.配制spring路径和struts路径

三、struts2文件配制

View Code
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 编码 -->
<constant name="struts.i18n.encoding" value="utf-8" />
<package name="User_Struts" extends="struts-default">
<action name="User_login" class="User_Action">
<result name="success">login.jsp</result>
<result name="input">login.jsp</result>
</action>
</package>
</struts>

struts.properties  属性配制   struts.action.extension=do   可以配制扩展名

四、相关日志文件

 

 
运行结果如下:

程序源代码下载地址:

http://download.csdn.net/source/3522031

你可能感兴趣的:(eclispe)