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.




No comments: