03 - Why to use Struts

Why to use Frameworks?

  • Using frameworks makes a programmer, code easy.
  • For example, if you want to build an application like Bank Management system, you have to gather all the  requirements first, you have to focus then on designing the layout of Bank Management system (including login page, display account information, withdraw form, deposit form, apply loan form etc.). After the designing phase is completed, you have to start translating the layouts into a programming language, that is you have to start implementing. Think of writing each and every task (module) independently. This obviously looks very tedious and there is no way to test single module until the complete project collaborates at the end. 
  • The main advantage of using framework is that, while you are implementing the project, certain predefined modules are available which you can import by adding just few lines of code.
  • For example, in Hibernate Framework Session and SessionFactory objects are automatically created at the time to web application deployment. Moreover, the persistent objects like Transaction and Query also help in direct communication with database as objects and not values. This concept is very advantageous, because as Java is Object -Oriented Programming language, the conversion of database values to objects and vice versa helps the easy communication with java objects of web application.
  • Similarly, in Struts Framework, there is ease of communication between data layer (Model), business logic can be easily implemented by using Interceptors (ActionServlets), Validation can be automatically implemented, file download and upload has direct implementation etc.
  • Frameworks are used to make the programmers’ focus more on business logic rather than displaying modules or handling databases.

Why to use Struts?

  • Struts Framework is a collaboration of JSP + Servlets + HTML + Database + POJO's (Plain Old Java Object – the java objects that are not bound to any specific programming language) + JSTL (JSP Standard Tag Library – for user defined tags) in one unit.
  • The framework thus results in very fast and efficient development of web applications with security and database integrity.
  • The framework creates applications that are flexible in nature, can be extended and modified easily without making changes in actual business logic. 
  • An input form validation is enabled by default in Struts. It asks the programmer for validation properties at the time of designing only.
  • Whenever a new java class is created, the class gets its features automatically added in xml configuration file. This facilitates programmer because large number of classes are to be created for a web application.

Advantages of Struts:

  • Struts make the web application development easy.
  • The framework is open source and freely available.
  • Powerful features of JSP API are included in Struts framework
  • It is very easy to use an inbuilt module – just inherit the properties by sub-classing the java class.
  • JSTL (JSP Standard Tag Library) provides the features of creating customized tags in Struts. These tags help the programmers to implement business logics easily by adding attributes to the tags as per requirement.
  • XML configuration files are automatically created for classes. Every time a new class is created, its configuration gets added to the XML file.
  • Thus the framework is flexible and easy to use. Maintenance is not much required until and unless under damaged conditions.
  • Images can be processed easily in Struts Framework. There is a separate module that handles image processing very efficiently.
  • Struts have extension for jQuery plugin (to provide the functionality for AJAX + User Interface facilities like Table Grid, Tree, Pane, Graphs and Charts).
  • Struts frameworks also have extension for JSF (Java Server Faces).
  • Struts have extension for Junit plugin (this plugin is used for testing purpose).
  • Hibernate extension is also available with Struts framework version 2.

Characteristics of Struts:

  • Open Source Framework
  • Design architecture of Struts framework is based on JSP Model 2 Architecture. So the existing JSP applications can be extended by shifting model 1 to model 2 architecture.
  • Custom tags: Rich set of JSTL custom tags helps programmers to extend the existing functionality.
  • Better Performance of Format classes such as NumberFormat, DateFormat, EmailFormat etc.
  • Incorporation of AJAX: makes the applications more dynamic.
  • Use of annotations can minimize the XML mapping code.
  • Struts can be extended for using in Spring Framework also.
  • The framework is pluggable which means that the flow of application is flexible.
  • The output file can be converted to PDF, XLS, DOC, and other formats easily. This is possible because Struts framework can integrate JasperReport, FreeMarker and other modules.
  • There is an easy conversion of HTML form data (HTTP data) to java basic objects. By this feature every HTTP form data can be manipulated using java functionality. The feature is known as type conversion.
  • Handling exceptions is easy in Struts framework. (for example : with <html:error> tag). Also, custom exceptions can be declared, thrown and catched easily.

 

Limitations of Struts:

  • To use Struts the programmer must be comfortable with using Java Servlet API as well as JSP (Java Server Pages).
  • It requires time to get familiar with the framework.
  • The framework is suitable for large web applications but not for small applications.
  • There is no proper documentation for Struts API available on internet. So programmers have to search for documentation, examples and framework tags a lot.
  • Every time the program is executed, variables, functions and tag values are stored in stack. So winding and unwinding the values on stack may cause performance issues.
  • The framework is very strict and while implementing it on web application, all the rules must be followed.
  • The applications developed using Struts frameworks are not thread-safe. That is synchronization is to manually maintained.
  • The applications are less transparent. That is, what’s going on behind while deploying the application is not very visible to programmer.
  • Migration from Struts version 1 to Struts version 2 is not very compatible.

Like us on Facebook