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>