1. Establish Maven project and guide the dependency package in pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lcz</groupId>
<artifactId>struts_spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.13</version>
</dependency>
</dependencies>
</project>
2. configuration inweb.xml
<filter>
<display-name> StrutSprePareandexecutefilter </Display-Name>
<filter-name> StrutSprePareandexecutefilter </filter-name>
<filter-class> org.apache.struts2.dispatcher.filter.StrutSprePareandexecuteFilter </Filter-Class>
</filter>
<filter-mapping>
<filter-name> StrutSprePareandexecutefilter </filter-name>
<url-Pattern>/*</url-Pattern>
</filter-mapping>
<!-It is used to initialize the Spring container during the launch of the web container->
<listener>
<listener-Class> ORG.SpringFramework.web.contextLoaderlistener </Listener-Class>
</listener>
<Context-Param>
<Param-name> ContextConfigLocation </param-name>
<Param-Value> ClassPath: Conf/Spring _*. XML </Param-Value>
</Context-Param>
3. Configuration of the Struts.xml file under Resources
<? Xml version = "1.0" encoding = "UTF-8"?>
<! Doctype Struts Public
"-Apache Software Foundation // DTD Struts Configuration 2.5 // EN"
"http://struts.apache.org/dtds/struts-5.dtd">
<struts>
<package name = "login" namespace = "/login" extends = "struts-default">
<!-Use the Action component webaction managed by Spring. During the configuration of Action, reference the Class attribute to the bean ID->
<action name = "web" class = "webaction">
<result name = "success">/web-inF/Success.jsp </result>
</enjoy>
</package>
</strongs>
4.Spring_web.xml configuration
<?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:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.1.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
">
<context:component-scan base-package="com.lcz.web"/>
</beans>
5.Webaction file
package com.lcz.web;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
@Controller
@Scope("prototype")
public class WebAction{
private String message;
public String getMessage() {
return message;
}
public String execute() {
System.out.println("Web action");
message="spring";
return "success";
}
}