加入Struts框架后的运行机制

尊重原创,文章: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时是同一个对象,故每次需要设计到线程同步问题。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值