Presentation is loading. Please wait.

Presentation is loading. Please wait.

APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.

Similar presentations


Presentation on theme: "APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional."— Presentation transcript:

1 APACHE STRUTS ASHISH SINGH TOMAR ast2124

2 OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional Features Summary

3 What is a Web Application Framework? “A structure for supporting or enclosing something else, especially a skeletal support used as the basis for something being constructed.”

4 What is Apache Struts? Struts is an open-source framework for building more flexible, maintainable and structured front-ends in Java web applications There are two key components in a web application: ◦the data and business logic performed on this data ◦the presentation of data Struts ◦helps structuring these components in a Java web app. ◦controls the flow of the web application, strictly separating these components ◦unifies the interaction between them

5 JSP/Servlet Web-Applications Traditionally, there are 3 ways to generate dynamic output (typically HTML or XML) in Java web applications: ◦Servlets  Java classes with some special methods ( doGet(), doPost(), … )  Example: out.println(" " + myString + " ");  no separation between code and presentation! ◦JSPs (Java Server Pages)  HTML (or other) code with embedded Java code (Scriptlets)  compiled to Servlets when used for the first time  Example:  better, but still no separation between code and presentation!

6 The Model-View-Controller Pattern Splits up responsibilities for handling user interactions in an application into three layers: ◦Model, View, Controller

7 The Model-View-Controller Pattern Model ◦holds application data and business logic ◦is absolutely independent from the UIs View ◦independent from the internal implementation of the Model ◦there can be different Views presenting the same Model data Controller ◦“bridge” between Model and View ◦controls the flow of the application  receives/interprets user input  performs operations on the Model

8 Struts Implementation of MVC

9 Controller ActionServlet manages the flow of the application ◦receives user requests and delegates them to the corresponding Action classes ◦selects the appropriate View to be displayed next (according to ActionForward returned by an Action class) Action ◦are Java classes that extend Struts’ Action class org.apache.struts.action.Action ◦The Action's execute() method is called by the ActionServlet ◦return an appropriate ActionForward object that tells the ActionServlet which View component it should forward to

10 Controller(cont.) ActionForm ◦are Java classes that extend Struts’ ActionForm class org.apache.struts.action.ActionForm ◦are filled with the form data by the ActionServlet ◦provide getter/setter methods to access them ◦Validation

11 External Configuration of struts-config.xml Example: <action path="/search" type="com.japp.SearchAction" name="searchForm" scope="request“ validate="true" input="/search.jsp"> Defines the control flow, the mapping between components and other global options: action-mappings form-beans Forwards plug-ins The entire logical flow of the application is in a hierarchical text file

12 View Technologies for View JSP Cocoon Swing Velocity Struts tag libraries ◦provide access to Model data ◦enable interaction with ActionForms ◦provide simple structural logic (such as iteration) ◦...

13 Model Holds the data of an application and provides business logic methods Model classes access and manipulates the data from database and return it to the invoker Action class The Model is usually built of different kinds of Business Objects: ◦JavaBeans  simple Java classes, that follow certain naming conventions  contain attributes and corresponding getters/setters  reside in the Web Container

14 Tiles Templates for Web pages ◦many different page components can be assembled to a “big” page  very useful when having content that is used on many different pages (e.g. sidebars) Layout various tiles of a web page ◦Header, Navigation, Body, Footer Specified in tiles-definition.xml ◦Specifies the layout ◦Logical names for various tiles ◦Associate filenames to the tiles

15 Tiles(cont.) Sketch the layout Make Template file that represents layout ◦Use tag to stub out sections that will be filled in by templates Create JSP pages that define layout pieces Create JSP pages that populate layout ◦Use tag to specify the layout pieces that apply to this specific page

16 i18n ◦Struts offers some features to easily internationalize an application ◦Text output can be defined in "resource bundles" that can be provided for many different languages ◦Struts automatically detects the users language through the HTTP request

17 Ajax Support ◦Only the part of the page that has to be processed will be transferred to the web server and the processed data will be loaded in the page without a page reload ◦Used mainly when cascading is required or high performance is required ◦Built in support: DWR and Dojo

18 Summary ◦Open source ◦ Good documentation ◦ Stable and Mature ◦Separation of Presentation and Business logic ◦Maintainability and Reusability of Code ◦Central Flow Control

19 THANK YOU!!


Download ppt "APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional."

Similar presentations


Ads by Google