Presentation is loading. Please wait.

Presentation is loading. Please wait.

Struts 2 introduction. Struts 2 framework Struts 2 A full-featured web application framework for the Java EE platform The Java Servlet API exposes the.

Similar presentations


Presentation on theme: "Struts 2 introduction. Struts 2 framework Struts 2 A full-featured web application framework for the Java EE platform The Java Servlet API exposes the."— Presentation transcript:

1 Struts 2 introduction

2 Struts 2 framework Struts 2 A full-featured web application framework for the Java EE platform The Java Servlet API exposes the HTTP client / server protocol to the Java platform. Struts 2 is built on top of the Java Servlet API layer. A framework makes generalizations about the common tasks and workflow of a specific domain. It then attempts to provide a platform upon which applications of that domain can be quickly built.  Struts 2  Java Servlet specification  HTTP

3 History of Struts Struts 2 Is from Apache software foundation  ASF is a non-profit corporation (decentralized community of developers) supporting Apache software projects including the Apache HTTP server. Struts 2 is a brand new web application framework  It is not just a new release of the Struts 1 framework, but a completely new framework based on the OpenSymphony WebWork framework. Struts 2 implements the popular Model-View- Controller (MVC) design pattern. The MVC pattern provides a separation of concerns that applies well to web applications. Separation of concerns allows us to manage the complexity of large software systems by dividing them into high- level components

4 Struts 2 implementation of the MVC Pattern  HTTP request  Web browser  client  Controller  FilterDispatcher  Model  Action  View  Result  invoke action  render page  select result Struts 2 MVC is realized by three core framework components : actions, results, and the FilterDispatcher

5 Struts 2 Request processing Struts 2 request processing uses interceptors that fire before and after the action and result Action Result invoke result ActionContext (ThreadLocal) ValueStackrequestsession … OGNL invoke actionfinished interceptors OGNL

6 Declarative architecture [1] Declarative architecture Is a type of configuration that allows developers to describe their application architecture (configure) at a higher level than direct programmatic manipulation Configuration occurs at two levels in Struts  As the Struts framework is flexible, it allows the developer to tweak its behaviour in many areas. This activity is actually configuring the behaviour of the Struts framework  The more important type of configuration (or declarative architecture) refers to defining the Struts 2 components that are used by your application and wiring / linking them together to form your desired workflow paths  Workflow paths refer to which action fires when a particular URL is hit, and which results might be chosen by that action to complete processing.

7 Declarative architecture [2] Multiple methods There are two methods of declaring the architecture of the application being developed  Through XML based configuration files  Through java annotations Whether the declaration is in XML or using java annotations, the framework translates them both into the same run time components  With XML, one has the familiar XML configuration document with elements describing the application actions, results and interceptors.  struts.xml struts.xml  With java annotations, the XML is gone. The metadata is located as java annotations inside the java source code for the classes that implement the Struts 2 actions. An annotated source file is shown below.  HelloWorldAction.java HelloWorldAction.java

8 URL mapping to struts actions [helloworldxml project] http:// + localhost:8080 + /helloworldxml + + /HelloWorld.action Protocol hostname:portnumber servlet context package name space action name.action The URL combines the servlet context with the package namespace and the action name. Note that the action name takes the.action extension. If the package name space is specified, that should be used as part of the struts action identifier URL, else it should be spaces.

9 Struts 2 data flow trace for the helloworldxml application Form rendered by index.jsp ValueStack HelloWorld Action String userName String message Form rendered by success.jsp

10 Struts 2 configuration Configuration files web.xml  Is a J2EE configuration file that determines how the elements of the HTTP request are processed by the servlet container. It is not a Struts 2 configuration file, but it is a file that needs to be configured for Struts to work struts.xml  Contains the configuration information that developer will be modifying as actions are developed. This is created under the directory WEB- INF/classes. struts-config.xml The struts-config.xml configuration file is a link between the View and Model components in the Web Client but you would not have to touch these settings for 99.99% of your projects. struts.properties This configuration file provides a mechanism to change the default behaviour of the framework. This file should be created in the WEB- INF/classes folder.Any line starting with # in this file is treated as comments.


Download ppt "Struts 2 introduction. Struts 2 framework Struts 2 A full-featured web application framework for the Java EE platform The Java Servlet API exposes the."

Similar presentations


Ads by Google