一 、 基本步骤 :
1. 引用的Jar包文件 :
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!--获取ServletAPI--> <dependency> <groupId>javaee</groupId> <artifactId>javaee-api</artifactId> <version>5</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.4.1</version> </dependency> <dependency> <groupId>org.apache.struts.xwork</groupId> <artifactId>xwork-core</artifactId> <version>2.3.4.1</version> </dependency>
2. 配置web.xml 文件
<!--Struts2 核心过滤器--> <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>
3. 视图层 这里只做截图展示:
4.
action层按照常规创建即可 ,需要实现 接口action :
package cn.happy.action; import com.opensymphony.xwork2.Action; /** * Created by lenovo on 2017/10/22. */ public class UserAction implements Action { public String execute() throws Exception { return SUCCESS; } }
5. 在resource 中增加 配置文件 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> <package name="default" namespace="/" extends="struts-default"> <action name="userAction" class="cn.happy.action.UserAction"> <result name="success">/success.jsp</result> </action> </package> </struts>