struts2一共有5类配置文件,分别是struts.xml、struts.properties、Web.xml、struts-plugin.xml和struts_default.xml。
(1)web.xml文件
准确的说Web.xml文件并不属于Struts2框架特有的文件。但是在Struts2框架中Web.xml文件是作为部署文件存在的,Web.xml是所有Java Web项目的核心文件。
在Struts 2框架当中需要在Web.xml文件中配置Struts2框架核心控制器(StrutsPrepareAndExecuteFilter),对Struts2框架进行初始化和处理所有的请求,Web.xml配置Struts2框架核心控制器(StrutsPrepareAndExecuteFilter)代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>StrutsDemo</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
在这里<filter>和<filter-mapping>里面的<filter-name>必须保持一致
(2)struts.xml文件
struts.xml定义应用自身使用的action映射及result,但我们一般将各个模块分配到不同的配置文件中。
未完待续。。。。。