1 / 19

APACHE STRUTS

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

otylia
Download Presentation

APACHE STRUTS

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. APACHE STRUTS ASHISH SINGH TOMAR ast2124

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

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

  4. 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 What is Apache Struts?

  5. 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("<H1>" + myString + "</H1>"); • 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: <H1><% out.println(myString); %></H1> • better, but still no separation between code and presentation! JSP/Servlet Web-Applications

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

  7. 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 The Model-View-Controller Pattern

  8. Struts Implementation of MVC

  9. 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 Controller

  10. 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 Controller(cont.)

  11. Example: <struts-config> <!– [...] --> <form-beans> <form-bean name="searchForm" type="com.japp.SearchForm"/> </form-beans> <action-mappings> <action path="/search" type="com.japp.SearchAction" name="searchForm" scope="request“ validate="true" <forward name="success“path="/next.jsp"/> input="/search.jsp"> </action> </action-mappings> <!– [...] --> </struts-config> • 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 External Configuration of struts-config.xml

  12. 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) • ... View

  13. 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 Model

  14. 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 Tiles

  15. Sketch the layout • Make Template file that represents layout • Use <tiles:insert> 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 <tiles:put> tag to specify the layout pieces that apply to this specific page Tiles(cont.)

  16. 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 i18n

  17. 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 Ajax Support

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

  19. THANK YOU!!

More Related