web.xml
java
<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服务器。只要是/*的请求路径,都交友Filte来处理、web
二、经过解析和反射struts2的核心Filter,实例化后,加载struts2的 相关配置文件,(strtus.xml)apache
经过解析struts.xml找到struts项目的主页服务器
<struts>app
<constant name="struts.enable.DynamicMethodInvocation" value="true" />jsp
<constant name="struts.devMode" value="true" />url
<package name="default" namespace="/" extends="struts-default">spa
<default-action-ref name="index" />code
<global-results>xml
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
<!-- 找到struts2的主页 -->
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
<include file="example.xml"/>
<!-- Add packages here -->
</struts>