项目结构
各类配置文件
1 <?xml version="1.0"?> 2 <!DOCTYPE hibernate-mapping PUBLIC 3 "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 4 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 5 6 <hibernate-mapping package="pojo"> 7 <class name="Product" table="product_"> 8 <id name="id" column="id"> 9 <generator class="native"> 10 </generator> 11 </id> 12 <property name="name" /> 13 <property name="price" /> 14 </class> 15 16 </hibernate-mapping>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE struts PUBLIC 3 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 4 "http://struts.apache.org/dtds/struts-2.0.dtd"> 5 6 <struts> 7 <constant name="struts.i18n.encoding" value="UTF-8"></constant> 8 9 <constant name="struts.objectFactory" value="spring"/> 10 11 <package name="basicstruts" extends="struts-default"> 12 13 <action name="listProduct" class="productActionBean" method="list"> 14 <result name="listJsp">list.jsp</result> 15 </action> 16 17 </package> 18 </struts>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:aop="http://www.springframework.org/schema/aop" 5 xmlns:tx="http://www.springframework.org/schema/tx" 6 xmlns:context="http://www.springframework.org/schema/context" 7 xsi:schemaLocation=" 8 http://www.springframework.org/schema/beans 9 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 10 http://www.springframework.org/schema/aop 11 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 12 http://www.springframework.org/schema/tx 13 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 14 http://www.springframework.org/schema/context 15 http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 16 17 <bean name="productActionBean" class="action.ProductAction"> 18 <property name="productService" ref="productServiceImpl" /> 19 </bean> 20 21 <bean name="productServiceImpl" 22 class="service.impl.ProductServiceImpl"> 23 <property name="productDAO" ref="productDAOImpl" /> 24 </bean> 25 <bean name="productDAOImpl" class="dao.impl.ProductDAOImpl"> 26 <property name="sessionFactory" ref="sf" /> 27 </bean> 28 29 <bean name="sf" 30 class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 31 <property name="dataSource" ref="ds" /> 32 <property name="mappingResources"> 33 <list> 34 <value>pojo/Product.hbm.xml</value> 35 </list> 36 </property> 37 38 <property name="schemaUpdate"> 39 <value>true</value> 40 </property> 41 42 <property name="hibernateProperties"> 43 <value> 44 hibernate.dialect=org.hibernate.dialect.MySQLDialect 45 hibernate.show_sql=true 46 hbm2ddl.auto=update 47 </value> 48 </property> 49 </bean> 50 51 <bean name="ds" 52 class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 53 <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 54 <property name="url" value="jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8" /> 55 <property name="username" value="root" /> 56 <property name="password" value="admin" /> 57 </bean> 58 </beans>
1 <web-app> 2 <filter> 3 <filter-name>struts2</filter-name> 4 <filter-class> 5 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 6 </filter-class> 7 </filter> 8 9 <filter-mapping> 10 <filter-name>struts2</filter-name> 11 <dispatcher>FORWARD</dispatcher> 12 <dispatcher>REQUEST</dispatcher> 13 <url-pattern>/*</url-pattern> 14 </filter-mapping> 15 16 <listener> 17 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 18 </listener> 19 20 </web-app>