You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Namespaces

Namespaces are an important concept that help manage large applications with hundreds of actions. Within the Web, namespaces are managed by paths. When a request comes in, the ServletDispatcher will extract the action and namespace to determine the appropriate action to execute. For more information regarding namespaces, please refer to the XWork documentation regarding namespaces (see Configuration). Below gives a short example of using namespaces with WebWork.

Note: If a request is made to /barspace/foo.action, the action foo will be searched for in a namespace of /barspace. If the action is not found, the action will then be searched for in the default namespace. Unless specified, the default namespace will be "". In our example below, their is no action foo in the namespace /barspace, therefore the default will be searched and /foo.action will be executed.

Namespace 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="bar" namespace="/barspace"> 

    <action name="bar" class="mypackage.simpleAction"> 
        <result name="success" type="dispatcher">bar2.jsp</result> 
    </action> 

</package>
  • No labels