1 / 10

Struts 2 introduction

Struts 2 introduction. 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.

noma
Download Presentation

Struts 2 introduction

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 2 introduction

  2. 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 Struts 2 framework

  3. 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 WebWorkframework. 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 History of Struts

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

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

  6. 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 thebehaviourof the Struts framework Declarative architecture [1] • 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. 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 Declarative architecture [2] • With XML, one has the familiar XML configuration document with elements describing the application actions, results and interceptors. • 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

  8. URL mapping to struts actions [helloworldxml project] http:// + localhost:8080 + /helloworldxml + <package name space> + /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 <s:formaction="/strutshello/HelloWorld.action"> <s:textfieldname="userName"label="User Name"/> <s:submit/> </s:form> ValueStack HelloWorld Action String userName String message Form rendered by success.jsp <h1><s:propertyvalue="message"/></h1>

  10. 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. Struts 2 configuration

More Related