Struts 2 Tip #2 - Use namespaces to organize your application into logical "modules"
Many Struts applications contain hundreds of pages. To help organize large applications, the Struts configuration is designed around the notions of "packages" and "namespaces". Each package can set its own defaults, including a namespace setting.
<struts> <package name="example" namespace="/example" extends="struts-default"> <action name="HelloWorld" class="example.HelloWorld"> <result>/example/HelloWorld.jsp </action> <!-- Add actions here --> </package> </struts>Use the namespace attribute to create logical modules or units of work within an application, each with its own identifying prefix. In an accounting application, the actions relating to "payables" might be in one namespace, and actions relating to "receivables" in another.
Namespaces avoid conflicts between action names. Each namespace can have it's own "menu" or "help" action, each with its own implementation. While the prefix appears in the browser URI, the tags are "namespace aware", so the namespace prefix does not need to be embedded in forms and links.
HTH, Ted.
Ted Husted is a software engineer and team mentor. His specialty is building agile web applications with open source products like Yahoo! User Interface Library, Struts, Spring, iBATIS, and MySQL, for either Java or Microsoft .NET, and helping others do the same.
Copyright Ted Husted 2007. All rights reserved.