1.导包
- struts2-core-2.3.31.jar
- xwork-core-2.3.31.jar
- ognl-3.0.19.jar
- log4j-core-2.3.jar
- log4j-api-2.3.jar
- javassist-3.11.0.GA.jar
- freemarker-2.3.22.jar
- commons-lang3-3.2.jar
- commons-io-2.2.jar
- commons-fileupload-1.3.2.jar
- asm-tree-3.3.jar
- asm-commons-3.3.jar
- asm-3.3.jar
2.在 src 目录下创建 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>
<!--配置action的访问后缀-->
<constant name="struts.action.extension" value="do,,"></constant>
<!--修改struts配置后自动加载struts文件 不需要重启tomcat-->
<constant name="struts.configuration.xml.reload" value="true"></constant>
<package name="default" namespace="/" extends="struts-default">
<action name="employee" class="com.ww.struts2.action.EmployeeAction" method="success"> //配置action(Servlet)类
<result name="success">index.jsp</result> //name属性的值与action的execute方法的返回值对应
</action>
</package>
</struts>
3.在web.xml中配置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>