Struts 2.0 学习笔记(1)

1.The framework uses a specific file as the entry point into this large description. This entry point is the struts.xml file. This file, which resides on the Java classpath, must be created by the developer. While it's possible to declare all your components in struts.xml, developers more commonly use this file only to include secondary XML files in order to modularize their applications.

2.tomcat is a servlet container.

3.WEB-INF also contains the central configuration file of all web applications, web.xml. This file, formally known as the deployment descriptor, contains definitions of all of the servlets, servlet filters, and other Servlet API components contained in this web application.

4.Actions do three things. First, as you probably understand by now, an action's most important role, from the perspective of the framework's architecture, is encapsulating the actual work to be done for a given request. The second major role is to serve as a data carrier in the framework's automatic transfer of data from the request to the view. Finally, the action must assist the framework in determining which result should render the view that’ll be returned in the request response.
Our actions hold the business logic, or at least the entry point to the business logic, and they should keep that logic as pure and brief as possible.

5.Struts 2 solves this problem by creating a new instance of an action for each request that maps to it. This fundamental difference allows Struts 2 objects to exist as dedicated data transfer objects for each request.

6.Package: The namespace attribute to "/chapterThree/secure". As we've seen, the namespace attribute is used to generate the URL namespace to which the actions of these packages are mapped.

7.If you don’t set the namespace attribute, your actions will go into the default namespace. The default namespace sits beneath all of the other namespaces waiting to resolve requests that don’t match any explicit namespace. Consider the following: http:// localhost:8080/manningHelloWorld/chapterSeventy/secure/AddImage.action If this request arrives at our sample web application, the framework will attempt to locate the /chapterSeventy/secure namespace. As this namespace doesn’t exist, the AddImage action won’t be found in it. As a last resort, the framework will search the default namespace for the AddImage action. If it’s found there, the URL resolves and the request is serviced. Note that the default namespace is actually the empty string "". You can also define a root namespace such as "/". The root namespace is treated as all other explicit namespaces and must be matched. It’s important to distinguish between the empty default namespace, which can catch all request patterns as long as the action name matches, and the root namespace, which is an actual namespace that must be matched.
命名空间例子
<package name="default">
    <action name="foo" class="mypackage.simpleAction">
        <result name="success" type="dispatcher">greeting.jsp</result>
    </action>

    <action name="bar" class="mypackage.simpleAction">
        <result name="success" type="dispatcher">bar1.jsp</result>
    </action>
</package>

<package name="mypackage1" namespace="/">
    <action name="moo" class="mypackage.simpleAction">
        <result name="success" type="dispatcher">moo.jsp</result>
    </action>
</package>

<package name="mypackage2" namespace="/barspace">
    <action name="bar" class="mypackage.simpleAction">
        <result name="success" type="dispatcher">bar2.jsp</result>
    </action>
</package>

/barspace/bar.action请求,将在/barspace命名空间下查找bar Action。如果发现了,bar Action将被运行。否则将会查找默认的命名空间。在上面的例子中,bar action定义在/barspace命名空间中,因此bar Action被执行,当返回"success"返回的时候,请求被定位到bar2.jsp。

/barspace/foo.action请求,将在/barspace查找foo Action,因为在/barspace命名空间下找不到,将在默认命名空间下查找,

moo.action请求,查找顺序是
根命名空间("/")
默认命名空间

因为moo Action确实存在,然后将被运行。

/foo.action,查找顺序
1根命名空间
2默认命名空间

对于/barspace/myspace/bar.action请求,查找顺序是
1./barspace/myspace命名空间
2.默认命名空间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值