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:
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:
- A client requests for a resource with URI that matches with the Action URI pattern defined in deployment descriptor file (web.xml).
- 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.
- ActionServlet looks for mapping for the path, If no mapping is found it throws an exception.
- 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.
- 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.
- Then servlet finds the Action type from mapping and instantiates Action class and calls to perform or execute method of Action class.
- Action class has a business logic implementation or it uses classes known as helper classes which has implementation of business logic.
- 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.
Labels: Java framework, MVC framework, struts
5 Comments:
This comment has been removed by the author.
Recemntly I have read some good articles on Struts at
http://www.interview-questions-tips-forum.net/index.php/Struts-Struts-2-Example-Tutorial
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
MVC Framework is good but MVVM is replacing it real fast :)
Nice post.We are providing Struts Online Training.for more visit STRUTS Online Training
Post a Comment
Subscribe to Post Comments [Atom]
<< Home