Google

Sunday, April 8, 2007

Introduction of struts MVC framework

Struts is a Java based web application framework which works on MVC design pattern. The project was created by Craig McClanahan in May 2000 and it is widely accepted and used Java framework.

The reason behind struts widely accepted is, ITs MVC framework. Struts clearly differentiates between different tiers of web applications. Model, View and Controller.

When request comes to server, web application container which could be Tomcat or weblogic or JBoss forwards request to ActionServlet. ActionServlet delegates request to one of the Action classes. Action classes generally have business logic defined or they call to helper classes which have implemented business logic.

Action class based on request performs business logic and forwards request to another Action class or returns to ActionServlet with ActionForward.

ActionForward is another Action URI, which is mapped to a JSP page which displays data.

So Action class works as Model, JSPs wok as View and ActionServlet works as controller which decides which Action class to instantiate based on request and then based on ActionForward decides on which JSP to be called. Other than that Struts also allows you to use Velocity or Tiles at view layer to make view layer more manageable.

Total work flow of struts framework:
  1. A client requests for a resource with URI that matches with the Action URI pattern defined in deployment descriptor file (web.xml).
  2. The web application container passes the request to ActionServlet.
    • ActionServlet gets instantiated when application is deployed. It reads struts-config.xml file and creates a configuration object. This configuration object is used to map request with resources like ActionForm bean or Action class.
    • That is why when struts-config.xml file changes, we need to redeploy the whole application so as to create a new configuration object.
  3. ActionServlet looks for mapping for the path, If no mapping is found it throws an exception.
  4. If the mapping specifies a form bean, the ActionServlet sees if there is one already or creates one. If the bean already is play, It resets and populates it from HTTP request.
  5. If the mapping has validate is set to true and Action bean has defined validate method, then it performs validation. If validation fails then servlet forwards request to input property of Action mapping with an error message.
  6. Then servlet finds the Action type from mapping and instantiates Action class and calls to perform or execute method of Action class.
  7. Action class has a business logic implementation or it uses classes known as helper classes which has implementation of business logic.
  8. The Action returns ActionForward to ActionServlet. ActionForward is another URI which is a JSP page in most cases. ActionServlet then forwards request to that JSP page which render response for the request and sends it to browser.
This is a detailed work flow of a typical struts application. Keep in touch i will be writing on Action classes and ActionFormBeans and other configuration in my next posts.

Labels: , ,

5 Comments:

Blogger Unknown said...

This comment has been removed by the author.

March 25, 2009 at 4:42 AM  
Blogger Unknown said...

Recemntly I have read some good articles on Struts at

http://www.interview-questions-tips-forum.net/index.php/Struts-Struts-2-Example-Tutorial

March 25, 2009 at 4:43 AM  
Blogger Unknown said...

Good knowledge on MVC framework, I am really fan of this blog and I have one more in list for the same http://www.tekhnologia.com

April 30, 2011 at 11:38 PM  
Blogger Abhinav Ranjan said...

MVC Framework is good but MVVM is replacing it real fast :)

June 17, 2011 at 2:16 PM  
Blogger johnson@smartmindonlinetraining.com said...

Nice post.We are providing Struts Online Training.for more visit STRUTS Online Training

May 8, 2015 at 3:38 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home