首先配置struts-config.xml位置在WEB-INF下面与web.xml同级
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="loginForm" type="com.bjsxt.drp.web.itemmgr.forms.LoginActionForm"/>
<form-bean name="itemForm" type="com.bjsxt.drp.web.itemmgr.forms.ItemActionForm"></form-bean>
</form-beans>
<global-exceptions>
<exception key="error.exception"
type="com.bjsxt.drp.business.util.AppException"
handler="com.bjsxt.drp.web.util.DrpExceptionHandler"
path="/WEB-INF/jsp/error.jsp"/>
</global-exceptions>
<global-forwards>
<forward name="index" path="/index.jsp" redirect="true"/>
</global-forwards>
<action-mappings>
<action path="/user/login"
type="org.springframework.web.struts.DelegatingActionProxy"
name="loginForm"
scope="request"
>
<forward name="sucess" path="/basedata/item.do?command=list&pageNo=1&pageSize=2" redirect="true"/>
</action>
<action path="/basedata/additem"
forward="/WEB-INF/jsp/basedata/item_add.jsp"
name="itemForm"
>
</action>
<action path="/basedata/item"
type="org.springframework.web.struts.DelegatingActionProxy"
name="itemForm"
scope="request"
parameter="command"
>
<forward name="modify_detail" path="/WEB-INF/jsp/basedata/item_modify.jsp"/>
<forward name="find_detail" path="/WEB-INF/jsp/basedata/item_detail.jsp"/>
<forward name="list_success" path="/WEB-INF/jsp/basedata/item_maint.jsp"/>
<forward name="upload_detail" path="/WEB-INF/jsp/basedata/item_upload.jsp"/>
</action>
<action path="/basedata/changelan"
type="org.springframework.web.struts.DelegatingActionProxy"
scope="request"
>
<forward name="success" path="/index.jsp" redirect="true"/>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
/
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
//
下面是hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate_struts_training_itemmgr</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="com/bjsxt/drp/business/itemmgr/model/DataDict.hbm.xml"/>
<mapping resource="com/bjsxt/drp/business/itemmgr/model/Item.hbm.xml"/>
</session-factory>
</hibernate-configuration>
//
下面是applicationContext—actions.xml(主要是处理Action的)
<?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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean name="/user/login" class="com.bjsxt.drp.web.itemmgr.actions.LoginAction"/>
<bean name="/basedata/item" class="com.bjsxt.drp.web.itemmgr.actions.ItemAction">
<property name="itemManager" ref="itemManager"/>
<property name="uploadPath">
<value>C://apache-tomcat-5.5.26//webapps//ssh_training_itemmgr//images//item//</value>
</property>
</bean>
<bean name="/basedata/changelan" class="com.bjsxt.drp.web.itemmgr.actions.ChangeLanguageAction"/>
</beans>
//
下面是applicationContext-beans.xml(专门定义<bean>标签)
<?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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="itemManager" class="com.bjsxt.drp.business.itemmgr.manager.ItemManagerImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="myfunction" class="com.bjsxt.drp.business.util.Functions">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
//
下面是applicationContext-common.xml(Spring 的基本配置)
<?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.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.bjsxt.drp.business.itemmgr.manager.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>
还有一些:log4j、国际化资源等等