Monday, 19 October 2009

What basically Struts2 is?














Struts2 is the latest manifestation of the popular Struts Java web application framework. Like its predecessor, its goals are to make web application development faster, easier and more productive than ever before.

Despite new languages and new techniques, the action-base MVC framework is still a viable and effective option for modern web application development

What framework is???

A framework tries to automate the common tasks and provides a platform for the users to build applications quickly.

Struts 2 framework implements the Model-View-Controller (MVC) design pattern. In Struts 2 the model, view and controller are implemented by the action, result and FilterDispatcher respectively. The controller's job is to map the user request to appropriate action. In Struts 2 FilterDispatcher does the job of Controller. Model contains the data and the business logic. In Struts 2 the model is implemented by the Action component. View is the presentation component of the MVC Pattern. In Struts 2 the view is commonly implemented using JSP, Velocity Template, Freemaker or some other presentation-layer technology.


The controller receives the user request and determine which Struts 2 action to invoke.

The framework creates an instance of this action and associate it with the newly created instance of the ActionInvocation.

In Struts 2 the invocation of action should pass through a series of interceptors as defined in the application's XML file.

The framework calls the ActionInvocations invoke() method to start the execution of the action.

Each time the invoke() method is called, ActionInvocation consults its state and executes whichever interceptor comes next.

ActionInvocation hands control over to the interceptor in the stack by calling the interceptors intercept() method.

The intercept() method of the interceptor inturn calls the invoke() method of the ActionInvocation till all the interceptors are invoked, in the end the action itself will be called and the corresponding result will be returned back to the user.

Some interceptor do work before the action is executed and some do work after the action is executed. It's not necessary that it should do something each time it is invoked.


Request Lifecycle in Struts 2 applications

  1. User Sends request: User sends a request to the server for some resource.
  2. FilterDispatcher determines the appropriate action: The FilterDispatcher looks at the request and then determines the appropriate Action.
  3. Interceptors are applied: Interceptors configured for applying the common functionalities such as workflow, validation, file upload etc. are automatically applied to the request.
  4. Execution of Action: Then the action method is executed to perform the database related operations like storing or retrieving data from the database.
  5. Output rendering: Then the Result renders the output.
  6. Return of Request: Then the request returns through the interceptors in the reverse order. The returning request allows us to perform the clean-up or additional processing.
  7. Display the result to user: Finally the control is returned to the servlet container, which sends the output to the user browser


No comments:

Post a Comment