1. 右键创建一个maven工程
2. 修改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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>Struct2</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Struct2 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- struts2核心依赖 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- struts2零配置依赖 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- struts2的json依赖 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>2.3.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- 查看部署的aciton信息 -->
<dependency><groupId>org.apache.struts</groupId>
<artifactId>struts2-config-browser-plugin</artifactId>
<version>2.3.20</version>
</dependency>
</dependencies>
<build>
<finalName>Struct2</finalName>
</build>
</project>
3. 部署运行 localhost:8080/index.jsp
4. 配置struts2,修改src/main/webapp/WEB-INF/web.xml文件, 主要是完成请求的过滤与分发
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<filter>
<filter-name>struts2</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>
</web-app>
5. 在WEB-INF文件夹下创建文件夹content,在content文件夹中创建first.jsp文件
6、在WEB-INF文件夹下创建classes文件夹,在classes或者src/main/resources文件夹中创建struts.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="xueyoupackage" namespace="/" extends="struts-default">
<action name="*">
<result>/WEB-INF/content/{1}.jsp</result>
</action>
</package>
</struts>
7.重新运行localhost:8080/first
8.action定义,修改struts.xml,创建com.test.TestAction.java文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="xueyoupackage" namespace="/" extends="struts-default">
<action name="TestAction_*" class="com.test.TestAction" method="{1}">
<result>/WEB-INF/content/first.jsp</result>
</action>
</package>
</struts>
9.重新运行localhost:8080/Struct2/TestAction_test.action