Top Banner
The Struts Framework Mohan Bang
24
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Struts presentation 1

The Struts Framework

Mohan Bang

Page 2: Struts presentation 1

Introduction

This Presentation will give you an overview of the Struts framework showing you the basic components you need to be familiar with in order to create a Web application using Struts.

Page 3: Struts presentation 1

Objectives

• Understand what is Struts and its benefits as an application framework

• Understand the Model-View-Controller design pattern

• Understand how an Struts application is composed

Page 4: Struts presentation 1

What are OO Application Frameworks?

• Frameworks are reusable, “semi-complete'' applications that can be applied to produce custom applications

• Frameworks are tested, proven software designs and implementations that reduce the cost, accelerate development speed and improve the quality of software

Page 5: Struts presentation 1

Benefits of using OO Application Frameworks

• Provide developers with modular, reusable and extensible software components

• Modular frameworks reduce the time and effort and investment required to understand and maintain existing software

• Fosters reuse. Contributes improvements in programmer productivity, as well as enhancing the quality, performance, reliability and interoperability of software

Page 6: Struts presentation 1

• Extensibility is essential to ensure timely customization of new application services and features

• Reduces the cost of building and maintaining software

Page 7: Struts presentation 1

Business benefits of using OO Frameworks & Tools

• Adherence to standards

• Uniformity of Code

• Accelerates Software Development

• Reduces cost of development and maintenance

• Reduces developer intervention

Page 8: Struts presentation 1

What is the Struts Framework?

• Struts is an open source framework created within the Jakarta project by the Apache Software Foundation

• Struts is a JSP/Servlet framework for building J2EE applications

• Struts accelerates application development based on the Model-View-Controller (MVC) design pattern

• For more info on struts go to:

http://jakarta.apache.org/struts/

Page 9: Struts presentation 1

What is the MVC Pattern?

• Is an abstract design pattern for software applications that was first introduced on the SmallTalk platform

• The goal of the MVC design pattern is to separate the application object (model) from the way it is represented to the user (view) from the way in which the user controls it (controller)

Page 10: Struts presentation 1

What are the components within the MVC Pattern?

• The model provides a representation of the data to the components comprising the view. It also knows about all the operations that can be applied to transform the data. It knows nothing about how it is being viewed by the users.

• The view provides presentation services in the application, such as a data entry screen or a screen rendering a query result .

Page 11: Struts presentation 1

• The controller is responsible for linking the view with the model. The controller can be thought of as the controlling influence on the state of the model. All paths of navigation in the application are channeled through the controller.

Page 12: Struts presentation 1

Benefits of using the MVC Pattern

• Widely accepted design pattern

• Modular

• Clarity of Design

• Easy to create multiple views of the business model

• Extensible

Page 13: Struts presentation 1

The MVC Used in Web Apps

• The MVC design pattern has now been adapted to build Web Applications.

• The adapted pattern is known as the Model2

• The model is represented by JavaBeans or EJBs

• The view is represented by JSPs

• The controller is represented by a Servlet.

Page 14: Struts presentation 1

What is the Struts Architecture?

• The model is comprised of a combination of EJBs, Java Beans, and a set of Java classes extending the Struts base class ActionForm

• The view is represented by JSPs.• The controller is implemented by the Struts

ActionServlet.• You can extend the controller’s behavior by creating

Action classes to trigger the execution of a user request.

• You integrate all these components by updating your web.xml file and the struts-config.xml file

Page 15: Struts presentation 1

What is the Struts Architecture? (Cont.)

• The view is implemented as JSPs that render presentation elements using both standard JSP tags and JSP Tag Extensions

• The use of JSP Tag Extensions eliminates the need for lots of messy processing logic and custom processing embedded in the presentation code

Page 16: Struts presentation 1

How to build a Struts application?

• Build the Model Components (ActionForm Class)

• Build the Controller Components (Action Class)

• Build the View Components (JSPs)

• Create the struts-config file

• Update the web.xml file

Page 17: Struts presentation 1

Building an ActionForm

• The ActionForm (also called the form) is a data holder that contains the data entered trough an HTML form.

• The form contains member variables related to each property that may be submitted within an HTML form.

• The form should also contain the get & set methods for each property.

Page 18: Struts presentation 1

• The form may also implement a validate method to perform data entry validations before actually performing the requested action.

• To create a form, you will need to extend the class org.apache.struts.action.ActionForm

Page 19: Struts presentation 1

Building an Action

• The Action is an object used to extend the behavior of the controller.

• An action implements a perform method that is called by the ActionServlet when an request is subimtted.

• A sample Action may be a SearchAction responsible for performing a DB query .

• Action classes should only process the data available in the form and should delegate the actual business processing to a JavaBean or EJB (model)

• To create an Action, you will need to extend the class org.apache.struts.action.Action

Page 20: Struts presentation 1

Building a JSP

• To create a JSP using Struts you will use the tag libraries provided by the Struts Framework.

• struts-logic.tld : This tag library contains tags that are useful in managing conditional generation of output text, looping over object collections for repetitive generation of output text, and application flow management.

• struts-html.tld : This taglib contains tags used to create struts input forms, as well as other tags generally useful in the creation of HTML-based user interfaces.

Page 21: Struts presentation 1

Building a JSP

• struts-bean.tld :This tag library contains tags useful in accessing beans and their properties, as well as defining new beans

• struts-template.tld : This tag library contains three tags: put, get, and insert. Put tags put content into request scope, which is retrieved by a get tag in a different JSP page (the template).

• You can get more information on the tag libraries at: http://jakarta.apache.org/struts/

Page 22: Struts presentation 1

Create the struts-config.xml file

• To allow for better reusability, all components in Struts are loosely coupled.

• To integrate the components you must create a config file (struts-config.xml)

• Within this file you’ll define the action-mappings and form-beans.

• The action-mappings tell the ActionServlet which action classes to include within the application.

• The form-beans define the ActionForm classes required within the application.

Page 23: Struts presentation 1

The web.xml file

• The final step in setting up an web application using Struts is to configure the application deployment descriptor (stored in file WEB-INF/web.xml) to include all the Struts components that are required.

• You will need to configure the Action Servlet Instance

• You will then configure the Action Servlet Mapping

• And you will configure the Struts Tag Library

Page 24: Struts presentation 1

Benefits of using Struts

• Encourages standardization of the presentation elements by promoting code reuse

• Offers an extensive collection of ready-to-use custom JSP tags

• Logic tags perform conditional processing, speeding development

• Proven architecture for building JSP/Servlet solutions