Showing posts with label Struts. Show all posts
Showing posts with label Struts. Show all posts

Monday, February 4, 2013

MVC in Sturts 2 and the flow of execution.

At first check  MVC funda

Suppose we want to create a application to show greetings for an interaction in by user. For this purpose, we can provide a page for initial interaction by the user. Suppose this page is index.jsp. This page contains a link by clicking which the user is able to get greetings from application. to so so we need to make following arrangements:


  1. Create a class to store the welcome message (the model)
  2. Create a server page to present the message (the view)
  3. Create an Action class to control the interaction between the user, the model, and the view (the controller)
  4. Create a mapping (struts.xml) to couple the Action class and view




How the code works here:
A browser sends to the web server a request for the URL 


  1. User send request by clicking on the link and in the link it is depicted which action will be implemented.
  2. The container receives from the web server a request for the depicted resource grettings.action. According to the settings loaded from the web.xml, the container finds that all requests are being routed to org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter, including the *.action requests. The StrutsPrepareAndExecuteFilter is the entry point into the framework.
  3. The framework looks for an action mapping named (i.e)"greetings", and it finds that this mapping corresponds to the class . The framework instantiates the Action and calls the Action's required method.
  4. The method creates the GreetingProvider (model) object and returns SUCCESS(feedback strings). The framework checks the action mapping to see what page to load if SUCCESS is returned. The framework tells the container to render as the response to the request, the resource welcome.jsp.
  5. As the page welcome.jsp is being processed, and the tag merges into the response the value of the required attributes.
  6. A pure HTML response is sent back to the browser.




Friday, February 1, 2013

MVC- Model View Controller

All the time we hear about it and the term itself made an image in mind. But still there is some fog in it. Recently i have got three definition regarding this three layers, and after that i am able to remove the fog about it:

MVC means Model-View-Controller where model is responsible for business logic, view handles the user interaction with application and controller decides the flow of application.
  • Model – A class which supplies the data needed for the application. 
  • View – A view element which displays the data.It displays the message returned by the Model class.
  • Controller – A controller class which will respond to user URL request. The controller will coordinate the actions of Model and the View. 


1) User sends the request using view which reaches to the controller on the server.
2) Controller decides the respective model and delivers the control to particular model.
3) As a result of business processing, model changes its state.
4) Depending on the state change of model, control redirects the flow to the view.
Main advantage of this architecture is the separation of data layer, presentation layer and pure business logic.

Tuesday, June 14, 2011

Model View Controller (MVC) design paradigm

Model-View-Controller (MVC) design paradigm, distinctly separating all three levels:

* Model: application state
* View: presentation of data
* Controller: routing of the application flow

In another way we can depicts as

The Model represents the business or database code, the View represents the page design code, and the Controller represents the navigational code.The original MVC pattern is like a closed loop: The View talks to the Controller, which talks to the Model, which talks to the View.