7 Best Practices of Struts

By: Emiley J.  

1. Extend When You Must

•Struts framework can be stretched and customized to allow for customized behavior.
•Configuration classes in the Struts framework (say, Struts configuration file , ActionServlet      RequestProcessor) can be substituted for a customized version.
•Declarative Exception Handling mechanism also allows for custom exception handlers to be used to better respond to application failures.
•Extension should be done judiciously.
•Before extending a Framework, we should always make sure that the functionality doesn't already exist  somewhere.

2. Use Application Modules

•Splitting of a single Struts application into multiple modules is allowed.
•This solves one of  the biggest complaints that development groups of more than a few people have had for some time because we can create Separate Struts Configuration Files for Individual Applications.
•Each Struts application module should  have its own configuration file. This allows us to configure separate Actions, ActionForms, exception handling, and much more, independent of other application modules.
3. Use Declarative Exception Handling

•Struts framework includes a class called ExceptionHandler.
•This class by default is responsible for processing any exceptions that occur during action execution.
•This class actually creates an ActionError object and stores it in the appropriate scope object.
•This allows the JSP pages to use the errors to inform the user of a problem.
•Customized ExceptionHandler classes can also be used.

4. Use a Base Action for your application

•Often, Actions in an application will need to perform some basic tasks.
•To ensure these tasks are implemented consistently, create a base Action that can be sub-classed by other actions in the application.

5. Check logins at the Controller Level


6. Use Validator Framework for validating user input

7. Use Custom tags instead of using scriplets and Java code in JSP pages


Most Viewed Articles (in Struts )

FAQ: Why are my checkboxes not being set from ON to OFF?

What is a Model View Controller (MVC) Model?

What is Struts? Which Version of Struts to use?

Origin and Architecture of Struts

Struts and Tiles - Steps to use Struts and Tiles

What is a Plug-in and how to use Java plug-ins with Struts?

Using Multiple Message Resource Bundles in Struts

Using Checkbox & Radio Tags, html:select, html:options in Struts Forms

Use of {0} is required and Accessing resource bundles programmatically in Struts

Handling multiple buttons in HTML Form in Struts

Handling Duplicate Form Submissions in Struts

DispatchAction in Struts

Guidelines for Struts Application Development

FAQ: Why was reload removed from Struts (since 1.1)?

Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices

Latest Articles (in Struts)

Comment on this tutorial

Subscribe to Tutorials

Related Tutorials

Archived Comments

1. Hi, my name is Jaime,
I wan't to do a jsp w

View Tutorial          By: Jaime at 2011-10-24 12:47:50

2. For Jaime,

Maybe using JavaScript f

View Tutorial          By: Jair Aviles at 2011-11-22 05:49:05

3. Hi,
Please give the better example of resou

View Tutorial          By: Keerthi at 2012-01-11 11:28:24

4. it is very useful and in understandable manner
View Tutorial          By: Deepika at 2012-03-26 05:10:15

5. Thanks very use full ..
View Tutorial          By: bal mukund at 2012-08-21 05:42:36

6. I want to redirect from a servlet page to another
View Tutorial          By: dinesh at 2014-10-20 16:44:26