You are on page 1of 19

Introduction to Struts

What is Struts
     

Framework to develop web applications Open source Based on MVC-Model 2 pattern Apache Jakarta Project Current release is 1.2.7 Developed in May 2000 and June 2001

What is Frame work




Frameworks are reusable, semicomplete'' 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

Benefits of Struts 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

Contributes improvements in programmer productivity, as well as enhancing the quality, performance, reliability of the software. Reduces the cost of building and maintaining software

What is the MVC Pattern?


 

MVC was first introduced by SmallTalk 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) i.e. layer architecture.

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. The view provides presentation services in the application, such as a data entry screen or a screen rendering a query result .

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 channelled through the controller.

What is MVC-Model 2
Controller
Form submit HTTP Event

Business Layer

Servlet
Create/Set property

Browser

Forward

Model JavaBean

View
HTTP Response Get property

JSP HTML Stylesheets

What is Struts MVC-Model 2


create Controller Http Event ActionServlet

ActionForm
dispatch Business Logic Action

Business Layer

Browser forward

StrutsConfig. xml forward

create/set

Resource Bundle

Model JavaBean

Http Response

View get JSP

What is 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.

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

Building an ActionForm


The ActionForm (also called the form) is a data holder that contains the data entered trough an HTML form. The form should also contain the get & set methods for each property. 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

Building an ActionServlet


ActionServlet is used to control the request and send the appropriate response to that request. It transforms request parameters into ActionForm There is only one ActionServlet in the application. Package is used
org.apache.struts.action.ActionServlet

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 HTMLbased user interfaces.

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 actionmappings 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.

Other Resources


Struts homepage


ttp://jakarta.apache.org/struts/ ttp://jakarta.apache.org Search criteria jakarta struts

The Jakarta Project




Search on ttp://www.google.com


Thanks Yashwant Chavan. ITShastra (INDIA) Pvt. Ltd.

You might also like