1.新建一个空白web项目

创建时要勾选创建xml文件选项

项目结构如下所示:

2.添加Structs2类库
在Apache官方网站下载相应版本的Sruts2,网址:http://struts.apache.org/,下载好后解压。
此处使用一些老版本的包,如下图

以下包拷贝到WebContent文件下的lib文件夹内,如下图所示:

3.配置web.xml文件,在web.xml中添加过滤器和默认配置文件,并设置为所有的请求(/*)都要通过这个过滤器,具体如下:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0"> <display-name>Structs2_app2</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>structs2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>structs2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
注意:按住ctrl键鼠标放置到filter-class节的类名上,出现下划线即可认为名称没有输错。