StrutsCatalog: Segment applications

Larger applications can often benefit from being organized into logical "segments" and using a separate set of configuration files for each segment. As of Struts 1.1. final, all Struts configuration files can be expressed as a comma-delimited list. Segments provide most of the benefits of using multiple modules without making it harder to share resources within the application.

The same general strategy is used for modules and segments. Each segment is given it's own "prefix", which acts like a namespace. The segment prefix is then made part of the


paths and Application Resource entries. Separate configuration files can be used for each segment (without using modules).


  <action path="/segment1/MyAction" ...  


  <action path="/segment2/MyAction" ...  


  <definition name=".segment1.MyDef"  


  <definition name=".segment2.MyDef"  

(Likewise for validator configurations.) = ... = ... 

Modules are useful when several teams are working independently, but if the application are being managed by a single, cooperate team, defining your own segments can be simplier and more effective.

For smaller applications, segments are also useful for creating a "command structure" format for your ActionMappings. It's been said that query strings are the universal command line. This is especially true of ActionMappings, which usually lead to some type of dynamic operation. Since ActionMappings can be named in any convenient manner, you can segment them after the command structure (which may also be embedded in the menu system). A set of mappings for a file management system might read "file/Save", "file/Open", and "file/Exit", regardless of how the source tree or JSP tree is organized.



  • No labels