Struts2 Tutorial Part 5 – Namespaces

In this session we will discuss about Struts2 namespaces.Struts2 namespaces are the Namespaces of the URL accessed.

For example if a user types types a URL  in that /struts2/action  is namespace and method.action  is the action name.

While naming a namespace we have to keep the below points in mind.

  • A namespace will be like “/path1/subpath”, “/path2/path3/sub1”.
  • A namespace can also be root namespace. (i.e) namespace=”/”. But it is exactly like normal namespace. The URL should match for it.
  • For example if the url is “” it will go to root namespace. If the url is “” it will go to “/path1/subpath” namespace.
  • We can also create default namespace where we can put default actions. That means if the requested action is not found in any specific namespaces then the control will look for that action inside the default namespace. The default namespace syntax will be
<package name="serveAll" namespace="" extends="struts-default">

One useful example of this default is we can handle all the unknown requests with the the simple setup like below.

<package name="serveAll" namespace="" extends="struts-default">
        <action name="*">

What we done is, if any requested action is not found simply responding with error page instead of file not found error. That’s why we put the action name as *. So even if the user types an action name asdasdasd it will respond with error.jsp . Even we can use wild card characters also in action name. In later chapters we will work on wild char characters in action names.

This entry was posted in Struts2 and tagged , . Bookmark the permalink.

One Response to "Struts2 Tutorial Part 5 – Namespaces"

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.