![Page 1: Struts Framework Anna Paščenko. What is Struts? An open source framework for building Java web applications](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/1.jpg)
Struts Framework
Anna Paščenko
![Page 2: Struts Framework Anna Paščenko. What is Struts? An open source framework for building Java web applications](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/11.jpg)
MVC architecture
![Page 12: Struts Framework Anna Paščenko. What is Struts? An open source framework for building Java web applications](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/12.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/13.jpg)
MVC architecture
![Page 14: Struts Framework Anna Paščenko. What is Struts? An open source framework for building Java web applications](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/14.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/15.jpg)
MVC architecture
![Page 16: Struts Framework Anna Paščenko. What is Struts? An open source framework for building Java web applications](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/16.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/17.jpg)
MVC Model 2
![Page 18: Struts Framework Anna Paščenko. What is Struts? An open source framework for building Java web applications](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/18.jpg)
Struts MVC
![Page 19: Struts Framework Anna Paščenko. What is Struts? An open source framework for building Java web applications](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/19.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/20.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/21.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/22.jpg)
Struts Architecture
![Page 23: Struts Framework Anna Paščenko. What is Struts? An open source framework for building Java web applications](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/23.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/24.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/25.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/26.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/27.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/28.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/29.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/30.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/31.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/32.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/33.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/34.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/35.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/36.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/37.jpg)
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](https://reader036.vdocuments.mx/reader036/viewer/2022070403/56649f325503460f94c4d8fa/html5/thumbnails/38.jpg)
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.