一、创建一个web工程,并导入相关jar包,(可以直接从struts-2.3.1.2\apps下的struts2-blank.war中的WEB-INF/lib目录下去copy)
二、创建Action:
public class HelloWorldAction implements Action{
public String execute() throws Exception {
System.out.println("HelloWorld!");
return SUCCESS;
}
}
三、新建success.jsp
四、在src目录下新建struts.xml,配置如下(配置的具体含义以后再一一介绍):
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="" namespace="/" extends="struts-default">
<action name="helloworld" class="com.test.struts2.HelloWorldAction">
<result name="success">success.jsp</result>
</action>
</package>
</struts>
<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>