目录
1.引入依赖(spring依赖 )
<dependency><!--spring核心--> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency><!--spring容器支持--> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency><!--spring容器支持--> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency><!--主要实现ioc模块--> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency><!--对web环境的支持和工具--> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency><!--aop相关--> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency><!--aop相关--> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency><!--aop相关--> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>4.3.2.RELEASE</version> </dependency> <dependency><!--数据库资源管理和错误处理--> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.3.2.RELEASE</version> </dependency>
(struts2依赖)
<!--struts2--> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.16</version> </dependency> <!--javaee--> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <!--jstl--> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <!--struts2-spring-plugin 版本号和struts2-core要一致--> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.3.16</version> </dependency>
2.web.xml配置
3.开发Action
public class UserAction extends ActionSupport { public String hello(){ System.out.println("action: hello"); return ActionSupport.SUCCESS; } }
4.工厂管理
<!--配置Action的bean,scope需要为prototype--> <bean id="userAction" class="com.baizhi.action.UserAction" scope="prototype"/>
5.配置struts.xml
<package name="hello" extends="struts-default" namespace="/hello"> <!--class为工厂中的id--> <action name="hello" class="userAction" method="hello"> <result name="success">/index.jsp</result> </action> </package>