Struts2的运行机制

来源:互联网 发布:java简历个人评价 编辑:程序博客网 时间:2024/06/01 12:48

当你在客户端敲http://localhost:8080/strust2_0100_Introduction/hello,这个url请求会通过HTTP协议发送给服务器TomcatTomcat收到请求之后,看收到的是哪个web applicationstrust2_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的核心:把请求和视图分开。分开的好处就是:增加灵活性

原创粉丝点击