struts framework anna paščenko. what is struts? an open source framework for building java web...

38
Struts Framework Anna Paščenko

Upload: archibald-gregory

Post on 05-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts Framework

Anna Paščenko

Page 2: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

What is Struts? An open source framework for building Java

web applications.

Page 3: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

A Good Framework is… A defined support structure in which another

software project can be organized and developed.

Page 4: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

A Good Framework is… A defined support structure in which another

software project can be organized and developed.

Allows to spend more time on meeting software requirements, not on more tedious low level details of providing a working system.

Page 5: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

A Good Framework is… A defined support structure in which another

software project can be organized and developed.

Allows to spend more time on meeting software requirements, not on more tedious low level details of providing a working system.

Provides proven and reliable design patterns and code architecture to an application.

Page 6: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Java Web Frameworks > 50 open source frameworks only

Struts Tapestry Spring Cocoon Maverick Echo

Page 7: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts One of the most popular and widely used Java

Web frameworks: stable and mature good documentation large user community open source developed by industry experts flexible and extendable

Page 8: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts Application architectures based on the Model 2

approach, a variation of the classic Model-View-Controller (MVC) design paradigm.

Page 9: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC architecture The MVC architecture divides applications into

three layers: model, view, controller

Page 10: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC architecture The MVC architecture divides applications into

three layers: model, view, controller

Each layer handles specific tasks and has specific responsibilities to the other areas.

Page 11: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC architecture

Page 12: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC architecture A model

represents business data and business logic or operations that access and modify this

business data

notifies views when it changes provides the ability for the view to query the model

about its state provides the ability for the controller to access

application functionality

Page 13: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC architecture

Page 14: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC architecture A view

renders the contents of a model accesses data from the model and specifies how

that data should be presented updates data presentation when the model changes forwards user input to a controller

Page 15: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC architecture

Page 16: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC architecture A controller

defines application behavior an application typically has one controller for each set of

related functionality

dispatches user requests selects views for presentation interprets user inputs and maps them into actions to

be performed by the model

Page 17: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

MVC Model 2

Page 18: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts MVC

Page 19: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts MVC Struts provides its own Controller component

and integrates with other technologies to provide the Model and the View.

Page 20: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts MVC For the Model, Struts can interact with

standard data access technologies (JDBC, EJB), most any third-party packages (Hibernate, iBATIS,

Object Relational Bridge etc.).

Page 21: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts MVC For the View, Struts works well with

JavaServer Pages, including JSTL and JSF, Velocity Templates, XSLT, etc.

Page 22: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts Architecture

Page 23: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts Controller Layer ActionServlet struts-config.xml Action ActionForward ActionForm

Page 24: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

ActionServlet Handles requests to a Struts application.

configured as Servlet in the web.xml file

Page 25: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

ActionServlet Handles requests to a Struts application.

configured as Servlet in the web.xml file specifies the url pattern to be handled by the servlet

Page 26: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

ActionServlet Handles requests to a Struts application.

configured as Servlet in the web.xml file specifies the url pattern to be handled by the servlet uses the configuration defined in struts-config.xml

file to decide the destination of the request

Page 27: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

struts-config.xml <form-beans>

describes a particular form bean, which is a JavaBean that implements the org.apache.struts.action.ActionForm class

Page 28: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

struts-config.xml<form-beans><!-- sample form bean descriptor for a DynaActionForm

<form-beanname="logonForm“

type="org.apache.struts.action.DynaActionForm"><form-property

name="username"type="java.lang.String"/>

<form-propertyname="password"type="java.lang.String"/>

</form-bean>end sample --></form-beans>

Page 29: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

ActionForm Encapsulates the form properties. Passed to an Action class methods as a

parameter.

Page 30: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

struts-config.xml <form-beans>

describes a particular form bean, which is a JavaBean that implements the org.apache.struts.action.ActionForm class

<global-forwards> configures the global mappings of logical names to

mappable resources

Page 31: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

struts-config.xml<global-forwards>

<forward

name="welcome"

path="/Welcome.do"/>

</global-forwards>

Page 32: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

ActionForward Represents a destination to which the controller

might be directed after finishing the processing activities.

Is a return value of the Action class methods.

Page 33: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

struts-config.xml <form-beans>

describes a particular form bean, which is a JavaBean that implements the org.apache.struts.action.ActionForm class

<global-forwards> configures the global mappings of logical names to

mappable resources <action-mappings>

contains action definitions

Page 34: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

struts-config.xml<action-mappings>

<action

path="/Login"

type="myPackage.LoginAction"

<forward name="forwardNext"

path="/pages/NextAction.jsp"/>

</action-mappings>

Page 35: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

ActionMapping Stores the mapping information. Passed to an Action class methods as a

parameter.

Page 36: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Action The Struts framework provides an abstract

Action class that you must extend for your own needs.

The ActionServlet calls the Action's execute() method to perform whatever task the Action class was meant to perform.

Within the overriden execute() method, you can put in whatever logic you need in order to fulfill the request.

Page 37: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Actionpublic class LoginAction extends Action {

/** * Called by the ActionServlet when the a user attempts to

login. */ public ActionForward execute(ActionMapping mapping,

ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

// Check username and password.return mapping.findForward("forwardNext");

}}

Page 38: Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications

Struts Examples Several example applications are bundled with

the Struts distribution: Blank - A simple template for starting new Struts

applications. MailReader - The original Struts example

application. Examples - Various demonstration applications

combined as separate modules.