Creating Struts Modules

By: Henry Emailed: 1704 times Printed: 2282 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

The objective of this tutorial is to teach how to create Struts application modules and break monolithic struts module into pieces

1. If you already have a Struts application, then this tutorial will show you how to add a new module to your existing application.

2. The index page belongs to the default module. From the index page, we will provide a link to go
to module2. Module 2 will consist of a two dummy pages that can call each other and also have a
link to return to default module.

  1. Change the web.xml to define a new module named xyz as follows:
    <init-param>
    <param-name>config/xyz</param-name>
    <param-value>/WEB-INF/struts-config-xyz.xml</param-value>
    </init-param>
  2. Copy over the struts-config.xml to create a new struts-config-xyz.xml
  3. Create a empty XYZ Message Resources
  4. Clean up the struts-config-xyz.xml to retain only empty blocks for form-beans, action
    mappings etc. Add the message resource bundle definition to struts-config-xyz.xml.
  5. Add SwitchAction to struts-config.xml & struts-config-xyz.xml as follows:
    <action path="/switch" type="org.apache.struts.actions.SwitchAction"/>
  6. Create a folder called xyz under the src/web directory. Create two jsps: xyz-page1.jsp & xyzpage2.jsp (Copy over index.jsp & change contents)
  7. Add bean:message for titles and define them in XYZMessageResources
  8. In xyz-page1.jsp, add link to navigate to xyz-page2.jsp (Forward Action via html:link)
  9. In xyz-page2.jsp, add link to navigate to xyz-page1.jsp (Forward Action via html:link)
  10. In index.jsp, a link is added to go to xyz-page1.jsp in xyz module as follows:
    <html:link forward="gotoXYZModule">Go to XYZ Module</html:link>
  11. In xyz-page1.jsp, add a link to go to index.jsp in default module
    <html:link forward="gotoDefaultModule">Go to Default Module</html:link>
  12. Add global forward in struts-config.xml to go to xyz-page1.jsp
    <forward name="gotoXYZModule"
    path="/switch.do?page=/page1.do&amp;prefix=/xyz" />
  13. Add global forward in struts-config-xyz.xml to go to index.jsp
    <forward name="gotoDefaultModule"
    path="/switch.do?page=/showCustomerSearchForm.do&amp;prefix="/>

Struts Home | All Struts Tutorials | Latest Struts Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(2)


1. View Comment

really nice explanation

View Tutorial          By: kuldeep at 2012-08-23 13:04:30
2. View Comment

Hi, Thanks a lot for this wonderful written steps. I searched a lot to get such explanation finally i found your article sweet and simple.
Keep posting such easily written steps.
thanks a lot... :)


View Tutorial          By: Amar at 2012-09-09 17:19:58

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Henry
Generating Your Key Pair example using keytool in Java
Summary of Operators in Java
JDBC Basics and JDBC Components
The IterationTag Interface in JSP
Trigonometric, Hyperbolic, Exponential and Logarithmic Functions in C
Using Bit-field in C
Java Beans and the Expression Language
Initialization of Variables in C
Creating Struts Modules
else if statement in C
Line Counting sample program in C
Accessing Context Data in Beans using JSF
Using peek() and putback() with cin in C++
Internationalization Support in J2ME MIDP
java.lang.SecurityException: MIDP lifecycle does not support system exit.

More Tutorials in Struts
Configuring JDBC DataSources in Struts
Struts Classes
FAQ: Why was reload removed from Struts (since 1.1)?
FAQ: Why are my checkboxes not being set from ON to OFF?
Using JavaScript to submit a form in Struts
How to prepopulate a form in Struts
Simple example of using the requiredif Validator rule in Struts
Chaining actions in Struts
When is the best time to validate input in Struts
What is a Plug-in and how to use Java plug-ins with Struts?
7 Best Practices of Struts
Origin and Architecture of Struts
ActionErrors and ActionError in Struts
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling multiple buttons in HTML Form in Struts

More Latest News
Most Viewed Articles (in Struts )
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling Duplicate Form Submissions in Struts
Struts and Tiles - Steps to use Struts and Tiles
Writing the first Struts application
ActionErrors and ActionError in Struts
Struts 1 vs Struts 2
Creating Struts Modules
Using Checkbox & Radio Tags, html:select, html:options in Struts Forms
Chaining actions in Struts
What is Struts? Which Version of Struts to use?
History of Struts
Editing web.xml in a Struts Application
Handling multiple buttons in HTML Form in Struts
DispatchAction in Struts
XDoclet struts-config.xml in Struts
Most Emailed Articles (in Struts)
Using Checkbox & Radio Tags, html:select, html:options in Struts Forms
ActionErrors and ActionError in Struts
History of Struts
The directories and files of a Struts application
Use ImageButtonBean for Image based Form Submits in Struts
ForwardAction in Struts
IncludeAction in Struts
What is a Model View Controller (MVC) Model?
Struts Classes
Editing web.xml in a Struts Application
Creating the first application using Struts 2
Struts 1 vs Struts 2
Model 1 Architecture
MVC with configurable controller
Introduction to Struts Architecture