GitHub 地址
訪問GitHub下載最新源碼:https://github.com/JYG0723/Struts2_Action
執(zhí)行流程圖
系統(tǒng)環(huán)境
IDE:InterliJ IDEA 2017.2.3
jdk 版本:1.8
Maven 版本:3.5
構(gòu)建
構(gòu)建好項目之后,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("執(zhí)行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>
注意:
- 出現(xiàn)的選項全勾
這樣簡單的 Struts2 的一個 Action 就配置完成了塔逃。自己編寫一個登錄實例琢歇,就可以進行測試了育韩。
url: http://127.0.0.1:8080/struts2/helloworld.action