Struts In Java

adplus-dvertising
Introduction of Struts2.0

The Apache Struts 2 framework is an elegant, flexible, secure, extensible and modern framework for creating enterprise-ready Java web applications. The framework is designed to fulfill all the desired needs of enterprise and streamline the full development cycle, from building, to deploying, to maintaining,testing and debugging applications over time to time. Apache Struts 2 was originally known as WebWork 2.

The struts framework was initially created by Craig McClanahan and donated to Apache Foundation inMay,2000 and Struts 1.0 was released in June 2001. The current stable release of Struts is 2.3.15. 1 GA in July 16, 2013.

Struts can be defined as a web application development framework that is based on the requests and is used in order to develop the web applications of java enterprise edition (Java EE). The struts framework is The very first Model View Controller (MVC) based framework and by the use of MVC the logic, view and user input related tasks gets separated and the work is done in a clear and consistent manner that can be verified and get maintained easily. The web framework of struts is known as the request response based web application framework.

Struts Tutorials and Interview Question
Features of Struts 2.0

The Apache Struts 2 framework provides many features that were not in struts1.The important features of struts 2 framework are as follows:

  1. Configurable MVC components:we can easily configure the MVC components in its configurations files like struts.xml and web.xml. It provide all the components and support.
  2. POJO based actions:In struts 2, action class is POJO (Plain Old Java Object) i.e. a simple java class. Here, you are not forced to implement any interface or inherit any class or not form a form bean class.
  3. AJAX support:Struts 2 provides support to ajax technology in its stable releases . It is used to make asynchronous request i.e. it doesn't block the user. It sends only required field data to the server side not all. So it makes the performance fast.
  4. Integration support:We can simply integrate the struts 2 application with hibernate, spring, tiles etc. frameworks.
  5. Various Result Types:We can use JSP, freemarker, velocity etc. technologies as the result in struts 2.
  6. Various Tag support:Struts 2 provides various types of tags such as UI tags, Data tags, control tags etc to ease the development of struts 2 application.
  7. Theme and Template support:Struts 2 provides three types of theme support: xhtml, simple and css_xhtml. The xhtml is default theme of struts 2.0 Themes and templates can be used for common look and feel.
Differences between struts 1.3x and 2.0

There are many differences between Struts1.3x and Struts2.0 as given below:

Struts1.3x:
  1. In this version we uses config file struts-config.xml” file to configure the struts controller. This file is need to create inside WEB-INF/ folder.
  2. The ActionForm(getter + setter) + Action class. like - LoginAction(action) / LoginForm
  3. The url pattern is like url - Login.do
  4. for struts validation it uses validation.xml,inside WEB-INF folder
  5. There is no concept for field label fieldError. like User Id
  6. There is no concept for required fields
  7. There is no support for collection framework for form designing
  8. There is no need of Action class for form design.
Struts2.0:
  1. In this version we uses config file struts.xml”. inside default package (outside url package).
  2. In Struts 2 only Action class (no need of ActionForm). getter & setter method inside Action class
  3. The url pattern is like url - Login.action / Login
  4. Struts2 with validation.xml file stored inside current package or with validate() method. It is best - with validate() method.
  5. For validations-1- with validation.xml, 2- with validate() method, 3- with Annotations
  6. Concept for field label fieldError.
  7. There is concept for required field
  8. There is support for collection framework for form designing
  9. There is need of Action class for form design. - major use
Advantages and disadvntages of struts 2

There are several Advantages and Disadvantages of Struts2.0 as given below:

Advantages:
  1. Simplified Design:Code is not tightly coupled to Struts framework or Servlet API.
  2. Easy plug-in:Developers can use other technologies plug-in easily. It includes SiteMesh, Spring, Tiles, etc.
  3. Simplified ActionForm:ActionForms are POJOs, we do not need to implement any interface or extend from any class.
  4. Annotations introduced:Use of annotation results in reduction in length and complexity of code. It is also used in configuration file for simplicity.
  5. Better tag features:It includes theme based tags and Ajax enabled tags.
  6. Simplified Testability: Unit testing of Struts 2 Action class is very easy because it doesn’t need complex HttpServletRequest and HttpServletResponse objects.
  7. Determine from the URI what action to invoke.
  8. Instantiate the action class.
  9. If an action object exists, populate the action's properties with request parameters.
  10. If an action object exists, call the action method.
  11. Forward the request to a view (JSP).
Disadvantages:
  1. Jar file required problem.
  2. XML file configuration problem
  3. Compatibility
  4. Limited Documentation
  5. Disadvantage Imposing