当你在客户端敲http://localhost:8080/strust2_0100_Introduction/hello,这个url请求会通过HTTP协议发送给服务器Tomcat,Tomcat收到请求之后,看收到的是哪个web application,strust2_0100_Introduction这个web application,找到后去执行这个web application下的web.xml
Tomcat接收到请求之后,会发现这个web.xml下面,配了一个filter,而这个filter过滤所有的url地址,所以当我们在地址栏敲http://localhost:8080/strust2_0100_Introduction/hello后,这个地址会被StrutsPrepareAndExecuteFilter接收到
<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>
StrutsPrepareAndExecuteFilter接收到后url情求后,它首先看namespace
Struts.xml
<packagename="default"namespace="/"extends="struts-default">
<actionname="hello">
<result>/hello.jsp</result>
</action>
</package>
查到“/”后面的hello,它就会去package下面查是否有name属性叫“hello”的action,有的话,找里面对应的result是什么--hello.jsp
Struts的核心:把请求和视图分开。分开的好处就是:增加灵活性