Reputation: 1631
I'm new in struts so I what know the meaning of "/" in namespace of package. i.e. when I put namespace as "/Home"
<package name="base" namespace="/Home" extends="struts-default">
<action name="HelloWorld" class="controller.HelloWorld">
<result>/message.jsp</result>
</action>
</package>
and type this Url : "localhost:8080/Struts2Example/Home/HelloWorld.action" on browser , then page opens.
but when I change the namespace to "Home" then it gives "Error : 404".
So what's this "/" means ?
Upvotes: 1
Views: 426
Reputation: 1631
Adding to user1428716 only "/" define the root name space.
<package name="base" namespace="/e" extends="struts-default">
<action name="HelloWorld" class="controller.HelloWorld">
<result>/message.jsp</result>
</action>
</package>
root is : "http://localhost:8080/Struts2Example/
"
so the url is "http://localhost:8080/Struts2Example/HelloWorld.action
"
and when we mention "/namespacename"
then it means "~root/namespaceName/your.action"
Upvotes: 0
Reputation: 2255
Here's some 101 on name spaces. The first thing you need to keep in mind is that namespace is not a file path.
Coming to what a namespace does: What happens is that when a user hits a request to access a struts web application, this url is splitted into hostname, port name, servlet context name, namespace (if any) and the struts action.
Ex. : localhost:8080/myapp/discountModule/getPrice.action
Namespace divides the action configuration into logical modules. For example if the URL /foo/myfoo/myfooaction.action is requested, the framework will first look for namespace /foo/myfoo. If the action does not exist at /foo/myfoo, the search will immediately fall back to the default namespace "". The framework will not parse the namespace into a series of "folders".
So when do we use names Spaces Namespace is very useful in large web application that need to seprated into small domains or modules. Example lets say you are managing a shopping cart backend and this has 4 main section - ADMIN, ORDERS, SALES & REFUNDS
As described earlier, namespace is defined inside the tag using namespace attribute. To define these four domain, four tag will be defined with their namespace specification as follows:
Ex - localhost:8080/shoppingCart/admin/doSomeAdmin.action
REMEBER - IT IS NOT MANADTORY TO USE A NAMESPACE.
Struts documentation has few more examples - http://struts.apache.org/release/2.1.x/docs/namespace-configuration.html
Upvotes: 1
Reputation: 2136
From Struts Manual http://download.oracle.com/otn_hosted_doc/jdeveloper/j2ee101302/working_with_struts/f1_struts_ide/f1_strutsconfigactionmappings.html
and here
http://struts.apache.org/release/2.1.x/docs/namespace-configuration.html
The request URI path which, when received by the Struts servlet action controller, invokes the action mapping. The path name is a relative path and must include the forward slash (/).
Upvotes: 1