尊重原创,文章:http://blog.csdn.net/chunlei_zhang/article/details/16368997
1)首先是在浏览器中输入网址,既要访问的url。根据http协议将连接请求发送给Tomcat等服务器.如url为:http://localhost:8080/ThridProject/hello
2)Tomcat服务器会将其进行分析,找到其应用程序为ThridProject,并查看ThridProject的web.xml文件,看是怎么配置的
3)这是在web.xml会存在这样的filter配置,该配置会过滤所有的url地址:
<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>
4)这个url地址就会被org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter类接收到,然后会看namespace,然后起Struts.xml中去查找namespace为“ /"的,而且Struts.xml的配置如下:
<package name="default" extends="struts-default" namespace="/">
<action name="hello">
<result type="dispatcher">/hello.jsp</result>
</action>
</package>
这个时候会查看是否存在hello.action,如果有则执行,并且跳转到result所指的jsp页面,若没有则跳转到默认的页面
5)将jsp页面的运行结果返回给浏览器
6)如果我们搜索的url的namespace没有找到就会返回给web.xml处理,如果web.xml会找到默认的网页如有以下配置:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Struts1和Struts2的区别:
1) Struts1的Action每次new时是同一个对象,故每次需要设计到线程同步问题。