GitHub 地址
访问GitHub下载最新源码:https://github.com/JYG0723/Struts2_Action
执行流程图
系统环境
IDE:InterliJ IDEA 2017.2.3
jdk 版本:1.8
Maven 版本:3.5
构建

构建好项目之后,maven 自动在webapp
目录下生成的东西,除了web.xml
全删。同时把web.xml
删除到只剩xsd
约束。
Pom
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.13</version>
</dependency>
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Action
public class HelloWorldAction extends ActionSupport {
@Override
public String execute() throws Exception {
System.out.println("执行Action");
// url: http://127.0.0.1:8080/struts2/helloworld.action
return SUCCESS; // = "success"
}
}
struts.xml

<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="helloworld" class="action.HelloWorldAction">
<result>/result.jsp</result>
</action>
</package>
</struts>

注意:
- 出现的选项全勾
这样简单的 Struts2 的一个 Action 就配置完成了。自己编写一个登录实例,就可以进行测试了。
url: http://127.0.0.1:8080/struts2/helloworld.action