Struts Basics


What is Struts2?
Struts is a framework based on set of Java technologies like Servlet, JSP, JSTL, XML etc which provides implementation of MVC architecture. The framework also provides ready to use validation framework. The power of Struts lies in its model layer by which Struts can be integrated with other Java technologies like JDBC, EJB, Spring, Hibernate and many more.

Struts is an open source framework developed by Apache Software foundationStruts can be broadly classified as Struts 1.X and Struts 2.X. Though Struts 2.X is successor of Struts 1.X, there is a vast difference between them. Struts 2.x is based on WebWorks2 framework. Struts 2.x is also called as pull-MVC architecture because data that needs to be displayed  to the user can be pulled from the Action(a class which contains business logic).

Struts follows Model 2 MVC Architecture :
  1. Controller: ActionServlet is the name of a class that plays role of controller in Struts. Whenever the user sends a request to server it passes via ActionServlet which then decide the necessary model and sends this request to the respective model.
  2. Model : Two more files support the flow of application: web.xml and struts-config.xml files. Web.xml file is deployment descriptor which keeps all the application related settings while struts-config.xml file maps a request to Action classes and ActionForms(a simple POJO which contains properties related to UI). Model is handled by various Java technologies like EJB, JDBC, Hibernate, Spring etc. It mainly concentrates on the business logic and semantics of the application.
  3. View : While view can be developed using JSP, Velocity Templates, JSTL, OGNL, XSLT and other HTML technologies. View is responsible for getting the input from the user and rendering the result of that input sent back to user.
Interceptors:
  1. Interceptors are an objects that dynamically intercept Action invocation.
  2.  It is invoked at the preprocessing and postprocessing of a request.
  3.  Interceptors provide a developer way to encapsulate common functionality in a re-usable that from one or more Action.
  4.  It is perform validations, exception handling, logger, intermediate results etc.