O SlideShare utiliza cookies para otimizar a funcionalidade e o desempenho do site, assim como para apresentar publicidade mais relevante aos nossos usuários. Se você continuar a navegar o site, você aceita o uso de cookies. Leia nosso Contrato do Usuário e nossa Política de Privacidade.
O SlideShare utiliza cookies para otimizar a funcionalidade e o desempenho do site, assim como para apresentar publicidade mais relevante aos nossos usuários. Se você continuar a utilizar o site, você aceita o uso de cookies. Leia nossa Política de Privacidade e nosso Contrato do Usuário para obter mais detalhes.
Struts Ppt 1 - Presentation Transcript<br />STRUTS Jaya Prakash...<br />Struts Agenda<br />Software Crises<br />What is Framework<br />Model1,Model2<br />What is Struts<br />Why we need it<br />Why is it called as Struts<br />Advantages of Struts<br />Terminology of Struts<br />Architecture of Struts<br />Controller Elements & it’s Responsibilities<br />Model Elements & it’s Responsibilities<br />View Elements & it’s<br />Responsibilities<br />Struts sequence diagram<br />I18n<br />Disadvantages<br />Challenges Exist In Software Development & Software Crisis<br />Projects must be developed Quickly.<br />Projects must be in High-Quality.<br />Application Stability.<br />Better code Maintainability.<br />Lower Cost for Developing Application.<br />To solve above Challenges<br />The Software Development Community Introduced Frameworks to Guide Development.<br />* Time shown with out day light savings<br />What is Framework<br />A software framework is a re-usable design for a software system (or subsystem).<br />A framework is a pre-built assembly of components and is designed to be extended.<br />It is also base for components.<br />Advantages of Framework<br />Provide a procedure for the development of Application.<br />Saves developers Time.<br />Provides same approach for all developers for developing code and Consistency in Software Design<br />Provide low-level services that developers can use to speedup development.<br />It also reduces software development and maintenance costs.<br />Most of the frameworks follow Model1,Model2<br />Model 1<br />In the Model 1 the JSP page is responsible for processing the incoming request and replying back to the client.<br />Disadvantages of Model1<br />It does not have separate controller<br />This Architecture usually leads to a significant amount of Java code embedded within the JSP page<br />Model 1 architecture is suitable for applications that have very simple page flow, have little need for centralized and change little over time.<br />Developers Designers JSP<br />Developers and designers must work on the same files!<br />Model 2<br />This Model2 approach combines the use of both servlets and JSP, using JSP to generate the presentation layer and servlets to perform process-intensive tasks.<br />Model2 architecture introduces a Servlet between the browser and the JSP pages.<br />The servlet acts as the controller and is in charge of the request processing and the creation of any beans or objects used by the JSP, as well as deciding, depending on the user's actions, which JSP page to forward the request to.<br />Model2 Advantages<br />No processing/business logic within the JSP page.<br />Model 2 applications are easier to maintain and extend, because views do not refer to each other directly.<br />The Model 2 controller servlet provides a single point of control for security and often encapsulates incoming data into a form usable by the back-end MVC model.<br />It also Provides unique responsibility to each component and each is independent of the other component .<br />Change in one component will have no or less impact on other components.<br />Model 2 Components and Responsibilities<br />Model<br />The Model portion of an MVC-based System responsible for internal state of the system, and actions that can be taken to change that state<br />Decide “ How to do ”<br />Controller<br />-Decide “ What to do ”<br />-The Controller portion of the application is focused on receiving requests from the client ,deciding what business logic is to be performed ,and then delegating responsibility for producing the next phase of user interface to an appropriate View Component<br />View<br />Presentation<br />What is Struts<br />An open source web application framework based on j2ee and java which implements the MVC design pattern is called Struts.<br />Why is it called as Struts<br />Strut synonym is Iron-rod.<br />Why we use and what are the advantages of Struts<br />It is open source.<br />Provides components for building Web Applications that speedup development and saves time for developers.<br />It makes complex applications into simple.<br />Built in Exception Handling<br />I18n support with resource bundles.<br />Built in validation framework.<br />It also have tiles framework (A template mechanism incorporated into struts for managing page layouts.)<br />Struts Architecture<br />Struts Framework Components<br />Controller Components - Direct the Action<br />Model Components - Access Data and Systems<br />View Components - What the users see<br />Struts Controller Components<br />Struts-config.xml<br />Actionservlet and Requestprocessor<br />Receive the HttpServletRequest<br />Automatically populate a JavaBean from the request parameters.<br />Handle Locale Issues<br />Determine which Action to invoke based on URI<br />Extends javax.servlet.http.HttpServlet<br />Receives all framework requests<br />Selects proper application module<br />Delegates request handling to the RequestProcessor instance<br />One ActionServlet instance per web application<br />Default implementation provided by Framework<br />Actionservlet and Requestprocessor<br />ActionServlet dispatch request to Request Processor(New from 1.1. previous this behaviour was in Action servlet)<br />The work of Request Processor is:-<br />Finding ActionMapping.<br />Mapping Action to FormBean.<br />Creating FormBean Object.<br />Calling reset() method of FormBean<br />Calling Validator of FormBean<br />If no form(jsp/html) validation errors calls execute method in Action Class and finding response to request.<br />If Errors give the errors on jsp present in input attribute of Action tag in struts-config.xml.<br />What is An Action Class<br />Extends org.apache.struts.action.Action<br />Overrides the execute() method<br />Acts as a bridge between user-invoked URI and a business method<br />Return information about which view should be rendered next<br />Part of the Controller ,not the Model<br />Actionclass Example<br />Struts-Config.xml<br />The power and flexibility of struts is due to the extracting of configuration information from across frame work.<br />Configuration file contains action mappings (determines navigation)<br />Controller uses mappings to turn HTTP requests into application actions<br />Mapping must specify<br />A request path<br />Object type to act upon the request<br />Tags in this file are:-<br />Data Sources.<br />Form Beans.<br />Global Exceptions.<br />Global Forwards<br />Actions<br />Controller<br />Message resources<br />Plug-in<br />Struts- Config.xml Example<br />The Model Components<br />Model Components<br />Java classes<br />middle tier components (EJB, Javabeans, …)<br />database access components<br />Used to represent the Internal state of the system<br />Actions that can change that state<br />Internal state of system represented by<br />JavaBeans<br />Enterprise JavaBeans<br />Action Form<br />Extends the ActionForm class<br />Create one for each input form in the application<br />It is just like a java bean, Store data temporary, reset default values to views, validate input view.<br />Hold state and behavior for user input.<br />If defined in the ActionMapping configuration file, the Controller Servlet will perform the following:-<br />Check for instance of bean of appropriate class<br />If no bean exists, one is created automatically<br />For every request parameter whose name corresponds to the name of a property in the bean, the corresponding setter method will be called<br />The updated ActionForm bean will be passed to the Action Class execute () method when it is called, making these values immediately available.<br />ActionForm Example<br />The View Components<br />Struts JSP Tag Libraries<br />HTML<br />Bean<br />Logic<br />Nested<br />Tiles<br />Template<br />Html Tag & Bean Tag Libraries<br />Tags used to create Struts input forms<br />Examples (checkbox,image,<br />link, submit ,text, text area)<br />Tags used for accessing JavaBeans and their properties<br />Examples (Define,message,write)<br />Logic ,Tiles & Nested Tag Libraries<br />Managing conditional generation of output text<br />Looping over object Collections for repetitive generation of output text<br />Example (empty,lessThan,<br />greaterThan)<br />Extended the base struts tags to allow them to relate to each other in nested nature<br />Tiles tags<br />Each part ("Tile") of webpage can be reused as often as needed throughout your application. This reduces the amount of markup that needs to be maintained and makes it easier to change the look and feel of a website.<br />Template Tag Library<br />The "struts-template" tag library contains tags that are useful in creating dynamic JSP templates for pages which share a common format. These templates are best used when it is likely that a layout shared by several pages in your application will change. The functionality provided by these tags is similar to what can be achieved using standard JSP include directive , but are dynamic rather than static.<br />Note: As of Struts 1.1 the template library has been deprecated<br />Action Message & Action Error<br />Used to signify general purpose informational and error messages<br />Rely on the resource bundles<br />JSP Tags can access them<br /></html:errors><br />Internationalization Support<br />Much of the framework functionality based on java.util.Locale<br />Struts Uses Java Resource Bundles .<br />Ex:-<br />Date ,Time and Currency Formatting<br />Currency Conversion<br />Resource Bundle Example<br />Other Features Suported by Struts Framework<br />Multi-Module Support<br />Declarative Exception-Handling<br />Dynamic Action Forms<br />Plugins<br />Tiles integrated With Core<br />Validator Integrated With Core<br />Struts Sequence Diagram<br />Struts Example<br />0.167.192.116login_app<br />Webapps|<br />|sample(Application Name)<br />|__ login.jsp<br />|__newLogin.Jsp<br />|__success.jsp<br />|__WEB-INF<br />|__web.xml<br />|__Struts-config.xml<br /> All the struts tld files|__*.tld <br />|__lib<br /> All the jar files|__*.jar <br />|__classes<br />|__LoginAction,LoginForm,<br />Messageresorces<br />Disadvantages<br />Bigger Learning Curve<br />Not Based on Domain Model<br />Property Names<br />Views are restricted .<br />Questions & Answers QUESTIONS & ANSWERS What did I Miss?<br />Thank u mail me:-email@example.com<br />