1 / 38

Struts Framework

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. A Good Framework is….

gitano
Télécharger la présentation

Struts Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 onmore tedious low level detailsof 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 onmore tedious low level detailsof 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. 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

  13. MVC architecture

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

  15. MVC architecture

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

  17. MVC Model 2

  18. Struts MVC

  19. Struts MVC • 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 patternto be handled by the servlet

  26. ActionServlet • Handles requests to a Struts application. • configured as Servlet in the web.xml file • specifies the url patternto 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 • <form-beans> • describes a particular form bean, which is a JavaBean that implements the org.apache.struts.action.ActionForm class

  28. struts-config.xml <form-beans> <!-- 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"/> </form-bean> end sample --> </form-beans>

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

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

  31. struts-config.xml <global-forwards> <forward name="welcome" path="/Welcome.do"/> </global-forwards>

  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 • <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

  34. struts-config.xml <action-mappings> <action path="/Login" type="myPackage.LoginAction" <forward name="forwardNext" path="/pages/NextAction.jsp"/> </action-mappings>

  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 overridenexecute() 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.

More Related