struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edward Seager <edward.sea...@gmail.com>
Subject Re: how does the namespace work in struts
Date Fri, 05 Nov 2010 16:22:42 GMT
Hi,

I've tried to answer your questions below based on my interpretation of the
documentation.

On Fri, Nov 5, 2010 at 8:33 AM, maven apache <apachemaven0@gmail.com> wrote:

> I meet some problem when I try to learn the namespace of struts2,I am using
> struts-2.2.1.
>
> After read the docs at:
> http://struts.apache.org/2.2.1/docs/namespace-configuration.html
>
> I am confused for the following reason:
>
> The example:
>
> <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>
>
> This is the explanation:
>
> *If a request is made to /barspace/foo.action, the namespace /barspace will
> be checked for action foo. If a local action is not found, the default
> namespace is checked. In the Namespace Example, there is no action foo in
> the namespace /barspace, therefore the default will be checked and
> /foo.action will be executed.*
>
> I wonder why it is '/foo.action' rather than 'foo.action",it said that it
> will find the foo.action at the default namespace,and the default namespace
> is "",so it should be foo.action,why there is a '/'??
>


I read this as, the default namespace is also relative to the context path.
so http://mycompany.com/myapp/foo.action. The default action has to be
relative to something afterall right? The difference between the default and
/ namespace is that the / namespace isn't checked in the fall back.



>
> ALso problem 2:
>
> *Namespace are not hierarchical like a file system path. There is one
> namespace level. For example if the URL /barspace/myspace/bar.action is
> requested, the framework will first look for namespace /barspace/myspace.*
>
> For the request url "/barspace/myspace/bar.action", the '/barspace/myspace'
> will be splitted as a namespace,so what is the action now? is it the
> "/bar.action" or "bar.action",since the "/" may stand for a root namespace.
>
> I am really confused,anyone can give me a detailed suggestion??
>
>
>
Namespaces not being hierarchical means that you do not have separate
namespaces for /barspace or /myspace in this case. Just one namespace for
/barspace/myspace. It's not like a directory structure on a file system. So
/barspace/myspace/bar.action will look up an action called bar in the
namespace /barspace/myspace/.

Hope this helps.


-- 
Eddy Seager

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message