Download presentation
Presentation is loading. Please wait.
Published byArchibald Gregory Modified over 9 years ago
1
Struts Framework Anna Paščenko
2
What is Struts? An open source framework for building Java web applications.
3
A Good Framework is… A defined support structure in which another software project can be organized and developed.
4
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.
5
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.
6
Java Web Frameworks > 50 open source frameworks only Struts Tapestry Spring Cocoon Maverick Echo
7
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
8
Struts Application architectures based on the Model 2 approach, a variation of the classic Model- View-Controller (MVC) design paradigm.
9
MVC architecture The MVC architecture divides applications into three layers: model, view, controller
10
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.
11
MVC architecture
12
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
13
MVC architecture
14
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
15
MVC architecture
16
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
17
MVC Model 2
18
Struts MVC
19
Struts provides its own Controller component and integrates with other technologies to provide the Model and the View.
20
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.).
21
Struts MVC For the View, Struts works well with JavaServer Pages, including JSTL and JSF, Velocity Templates, XSLT, etc.
22
Struts Architecture
23
Struts Controller Layer ActionServlet struts-config.xml Action ActionForward ActionForm
24
ActionServlet Handles requests to a Struts application. configured as Servlet in the web.xml file
25
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
26
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
27
struts-config.xml describes a particular form bean, which is a JavaBean that implements the org.apache.struts.action.ActionForm class
28
struts-config.xml <!-- sample form bean descriptor for a DynaActionForm <form-bean name="logonForm“ type="org.apache.struts.action.DynaActionForm"> <form-property name="username" type="java.lang.String"/> <form-property name="password" type="java.lang.String"/> end sample -->
29
ActionForm Encapsulates the form properties. Passed to an Action class methods as a parameter.
30
struts-config.xml describes a particular form bean, which is a JavaBean that implements the org.apache.struts.action.ActionForm class configures the global mappings of logical names to mappable resources
31
struts-config.xml <forward name="welcome" path="/Welcome.do"/>
32
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.
33
struts-config.xml describes a particular form bean, which is a JavaBean that implements the org.apache.struts.action.ActionForm class configures the global mappings of logical names to mappable resources contains action definitions
34
struts-config.xml <action path="/Login" type="myPackage.LoginAction" <forward name="forwardNext" path="/pages/NextAction.jsp"/>
35
ActionMapping Stores the mapping information. Passed to an Action class methods as a parameter.
36
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.
37
Action public 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"); }
38
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.