1,web.xml中配置struts2
1.1,使用默认的struts2配置文件:src/struts.xml
web.xml
<filter>
<filter-name>struts2</filter-name> <!-- 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>
1.2,使用指定的struts2配置文件
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name> <!-- param-name不可自定义 -->
<param-value>
struts-plugin.xml, <!-- 自己指定struts2配置文件时,struts-plugin.xml和struts-default.xml必须显示指定 -->
struts-default.xml,
../struts.xml, <!-- 配置文件名可自定义 -->
../struts-login.xml <!-- 必须采用相对\WEB-INF\classes的相对路径,且不能用通配符,如../struts-*.xml -->
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
等同于下面的web.xml + struts.xml
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>
../struts.xml,
../struts-login.xml
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
struts.xml
<include file="struts-plugin.xml"/> <!-- <include>在引用时是单独解析的xml文件,而不是将被引用的文件插入到struts.xml文件中。 -->
<include file="struts-default.xml"/> <!-- 用<include>引用的xml文件也必须是完成,有头有尾。 -->
2,web.xml中配置spring
2.1,使用spring默认配置文件:WEB-INF/applicationContext.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.2,使用自己指定的spring配置文件:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name> <!-- param-name名字不可改变 -->
<param-value>
/WEB-INF/spring.xml, <!-- 可以使用spring的 <importresource=""/> 标签来进行配置文件嵌套 -->
/WEB-INF/spring-*.xml <!-- 配置文件名字可自定义,可以使用通配符 -->
</param-value>
</context-param>
3,spring配置文件中配置ibatis
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/TRAINING</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>
/WEB-INF/ibatis.xml <!-- 配置文件名字可自定义 -->
</value>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
4,ibatis配置文件中配置sqlMapConfig
<sqlMapConfig>
<sqlMap resource="com/dao/ibaties/map/User.xml" /> <!-- 路径和xml名由自己定义-->
</sqlMapConfig>