spring4.1.6整合Struts2.5.5
–前言
- 准备条件
- 导入必要的jar包
- 编写web.xml文件
- 编写struts.xml文件
- 编写spring.xml文件
- 编写log4j2-test.properties文件
- 编写测试Aciton类
- 编写jsp页面
- 发布到tomcat8.0服务器
- 启动服务器并访问对应的jsp页面
- 总结
前言
本文是介绍整合struts2.2.5和spring4.1.6的文章。本文通过9个步骤搭建
一个最小的struts2.2.5和spring4.1.6的框架。其中也有log4j2的配置。
本文需要编写的文件有web.xml, spring.xml, log4j-test.properties,struts.xml, UserAction.java, login.jsp6个文件。
通过本文可以学会搭建struts和spring的最小框架。
准备条件
struts2.2.5相关jar包,spring4.1.6相关jar包,tomcat8.0
服务器和eclipse集成IDE,读者可自行到各大官网下载依赖的jar包
导入jar包
需要导入的jar包如下图所示:
编写web.xml文件
编写必要的web.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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="ssheWebApp" version="2.5">
<display-name>TestSystem</display-name>
<!-- 配置需要初始化的xml文件,不配置时默认加载applicatinContext.xml -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<!-- 配置struts2的核心拦截器,官方推出用StrutsPreparedAndExcuteFilter代替FilterDispatcher -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPreparedAndExcuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置sp