1 / 27

UNIT-V The MVC architecture and Struts Framework

UNIT-V The MVC architecture and Struts Framework. Agenda. Introduction to MVC architecture. Introduction to Struts Framework. Anatomy of simple struts Application. Struts-config.xml file. Presentation layer with JSP.

jayden
Download Presentation

UNIT-V The MVC architecture and Struts Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UNIT-VThe MVC architecture and Struts Framework

  2. Agenda • Introduction to MVC architecture. • Introduction to Struts Framework. • Anatomy of simple struts Application. • Struts-config.xml file. • Presentation layer with JSP. • Struts Controller Class, JSP bean, HTML and logic tag libraries. • Action forms, Dynamic action form, Actions, forwarding. • Simple application using struts framework

  3. Introduction to MVC architecture • Model–view–controller (MVC) is a software architecture, currently considered an architectural pattern, used in software engineering. • The pattern isolates domain logic (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing and maintenance of each (separation of concerns).

  4. Use of the MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

  5. What is framework and why • Framework is set of reusable software program that forms the basis for an application. • Frameworks helps the programmers to build the application quickly. • Earlier it was very hard to develop complex web applications. • Now its very easy to develop such application using different kinds of frameworks such as Struts, Struts 2, Hibernate,  JSF, Tapestry, JUnit, Log4j, Spring etc.

  6. Software framework • Framework software in computer system is a layered structure that indicates what kind of program should be built and how they would interrelate to one another. • In computer system, a framework is a conceptual structure that sometime includes actual programs, which specify programming interface or offer programming tools for using the frameworks.

  7. Struts framework- prerequisite • HTML, Java Script • JSP • Servlet • Java Bean • Tag Libraries under JSP • XML

  8. Introduction to StrutsFramework • Strutsframework: is an open-sourceweb application framework for developing Java EEweb applications. It uses and extends the Java ServletAPI to encourage developers to adopt a model-view-controller (MVC) architecture.

  9. The goal of Struts is to separate the model (application logic that interacts with a database) from the view (HTML pages presented to the client) and the controller (instance that passes information between view and model). • Struts provides the controller (a servlet known as ActionServlet) and facilitates the writing of templates for the view or presentation layer (typically in JSP, but XML/XSLTandVelocity are also supported).

  10. Struts framework and Model • Model is responsible for providing the data from the database and saving the data into the data store. • All the business logic are implemented in the Model. • Data entered by the user through View are check in the model before saving into the database. • Data access, Data validation and the data saving logic are part of Model

  11. Struts framework and View View represents the user view of the application and is responsible for taking the input from the user, dispatching the request to the controller and then receiving response from the controller and displaying the result to the user. • HTML, JSPs, Custom Tag Libraries and Resourcesfiles are the part of view component.

  12. Struts framework and Controller • Controller is intermediary between Model and View. Controller is responsible for receiving the request from client. • Once request is received from client it executes the appropriate business logic from the Model and then produce the output to the user using the View component. • ActionServlet, Action, ActionForm and struts-config.xml are the part of Controller.

  13. The web application programmer is responsible for writing the model code, and for creating a central configuration file struts-config.xml that binds together model, view and controller.

  14. Requests from the client are sent to the controller in the form of "Actions" defined in the configuration file; if the controller receives such a request it calls the corresponding Action class that interacts with the application-specific model code.

  15. The model code returns an "ActionForward", a string telling the controller what output page to send to the client. • Information is passed between model and view in the form of special JavaBeans. • A powerful custom tag library allows it to read and write the content of these beans from the presentation layer without the need for any embedded Java code. • Struts is categorized as a request-based web application framework.

  16. Struts framework provides three key components: • A request handler provided by the application developer that is used to  mapped to a particular URI (Uniform Resource Identifier). • A response handler which is used to transfer the control to another resource which will be responsible for completing the response. • A tag library which helps developers to create the interactive form based applications with server pages.

  17. Anatomy of Struts Framework

  18. Process flow • web.xml : Whenever the container gets start up the first work it does is to check the web.xml file and determine what struts action Servlets exist. • The container is responsible for mapping all the file request to the correct action Servlet.  • A Request : This is the second step performed by the container after checking the web.xml file. • In this the user submits a form within a browser and the request is intercepted by the controller. 

  19. The Controller : This is the heart of the container. Most Struts application will have only one controller that is ActionServlet which is responsible for directing several Actions. • The controller determines what action is required and sends the information to be processed by an action Bean. • The key advantage of having a controller is its ability to control the flow of logic through the highly controlled, centralized points. 

  20. struts.config.xml : Struts has a configuration file to store mappings of actions. • By using this file there is no need to hard code the module which will be called within a component. • The one more responsibility of the controller is to check the struts.config.xml file to determine which module to be called upon an action request. Struts only reads the struts.config.xml file upon start up. 

  21. Model : The model is basically a business logic part which takes the response from the user and stores the result for the duration of the process. • This is a great place to perform the preprocessing of the data received from request. It is possible to reuse the same model for many page requests. • Struts provides the ActionForm and the Action classes which can be extended to create the model objects.

  22. View : The view in struts framework is mainly a jsp page which is responsible for producing the output to the user. • Struts tag libraries : These are struts components helps us to integrate the struts framework within the project's logic. These struts tag libraries are used within the JSP page. This means that the controller and the model part can't make use of the tag library but instead use the struts class library for strut process control.

  23. Property file : It is used to store the messages that an object or page can use. Properties files can be used to store the titles and other string data. We can create many property files to handle different languages.  • Business objects :  It is the place where the rules of the actual project exists. These are the modules which just regulate the day- to- day site activities. • The Response : This is the output of the View JSP object.

  24. Let us work with simple application using struts framework.

  25. Thank you

More Related