Do Struts2 namespaces have to start with a forward slash?

529 Views Asked by At

I use the Struts2 framework for webapp development. In every tutorial I encounter, I see that all namespaces start with a forward slash /. Even the basic "default" namespace has the namespace "/" instead of the empty string "" or the string "default". Why is that? Is it possible to just name the namespace without the slash?

It looks like it can't, because I get error that actions can no longer be found if I change the namespace from "/" to "something else":

Struts Problem Report

Struts has detected an unhandled exception:

Messages: There is no Action mapped for namespace [/] and action name [] associated with context path [/TestStruts].

1

There are 1 best solutions below

0
On

A slash is important to the namespace, because the action mapper can extract namespace and action name from the URL using last slash.

Note, that if you use slashes in action name and always select full namespace are configured, the algorithm might change.

But you can use a package declaration without namespace attribute. In this case all actions in that package will belong to "default" namespace.