To make a web application more productive when using Struts2, there are some techniques and tips. This article will provide you an introduction to some of these tips. which are,

 

Reuse the configurations of action

 

Actions can be configured into packages. And extension of this packages to other packages is also possible. It is better to configure and provide a base action in the default package. The same action has been accessed by every inheriting package.

 

Pattern Matching Wild cards can be used in configurations

 

Sometimes the action configuration files can grow to very large size in a shorter period of time. Using the pattern matching is one of the solutions for this phenomenon. Pattern matching’s working is like that, by defining some patterns which will agree by the URLs.

 

Make use of alternate ‘URI Mapping Schemes’

 

To reduce the configuration we can use URI to action custom mapping, instead of using the ‘wild cards’ in the configurations. For the entire application we can make use of this mapping approach.

 

Know the functionality of the Interceptors

 

Interceptors role is very crucial in Struts2 framework, to provide the functionality. We need to know about each interceptor that is available. Thus we will get a clear picture about each processing step of an action.

 

Use the Result Types

 

By using the result types, developers can determine the way of result to the user. Different result types can be used for the configuration of multiple results from one action.

 

Make advantage of Data Conversion

 

Struts2 provides data conversion for us to convert the String type data to any other type of data(String, Boolean, int,char,float,long, double,Date etc) for business methods or the model.

 

Make use of Tabular Data Transfer Technique

 

Struts2 give a great way(for using lists) to transfer the data which is tabulated, between actions and the user interface(HTML).

 

Utilize ‘Declarative Validations’ where ever we can

 

Programmatic and declarative validations are possible in Struts2. For the extremely complex validations only we need this programmatic validations. Otherwise it is better to use the declarative validations.

 

Make use of annotations where ever we can

 

For the configuration we can make use of annotations. For avoiding the action XML configuration we can utilize the annotation support. And there is a chance to avoid the whole configuration file (Struts.xml), if we extend from the active package always.

 

Some Supports in ‘View Technologies’

 

We can make use of the tag libraries in view technologies like Freemarker templates and Velocity. In Struts2, it is possible to utilize different types of views in the same action(same project).

 

So, now using this article you can think about interaction of one tip to another and differences of these tips and finally you can come up with the way that you can utilize this tips in your development.