Struts2 基本配置

1. 首先在web.xml文件中加入struts默认过滤器,从而将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>

  

    在上面的配置文件中过滤器映射中指定了struts要过滤的所有url路径,/*表示对多有请求进行过滤,所以当请求中含有匹配的action时将交由struts框架进行处理;
2. 导入struts相关的jar文件到WEB-INF/lib文件夹下,并加入到项目中,需导入的jar文件如下:
3. 在src目录下添加struts.xml文件,该文件是struts的默认配置文件,可以在该文件中配置action、相关资源等,模板文件如下:
<?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">

    </package>
</struts>

  

如上过程就完成了struts的配置。
原文地址:https://www.cnblogs.com/lvniao/p/5511931.html