+ All Categories

Struts

Date post: 28-Jan-2015
Category:
Upload: rajkumar-singh
View: 1,025 times
Download: 0 times
Share this document with a friend
Description:
 
Popular Tags:
27
Struts Workshop Presented By Rajkumar Singh www.rajkrrsingh.blogspot.c
Transcript
Page 1: Struts

Struts Workshop

Presented ByRajkumar Singh

www.rajkrrsingh.blogspot.com

Page 2: Struts

Agenda

www.rajkrrsingh.blogspot.com

Struts 2 overview Request ,Response cycle Struts 2 architecture Struts 1 vs Struts 2 Struts2 Tags Validator framework Interceptor and Custom Interceptor ValueStack, OGNL and Type Converter

Page 3: Struts

MVC

www.rajkrrsingh.blogspot.com

Page 4: Struts

What is Struts2 Framework

www.rajkrrsingh.blogspot.com

A framework tries to automate the common tasks and provides a platform for the users to build applications quickly.

Page 5: Struts

What is Struts2 Framework

www.rajkrrsingh.blogspot.com

Struts 2 is a very well-designed and flexible. An integration of Struts 1 with OpenSymphony Web Works Framework

Page 6: Struts

What is Struts2 Framework

www.rajkrrsingh.blogspot.com

Struts 2 framework implements the Model-View-Controller (MVC) design pattern. –Model- use any data access technologies like JDBC, EJB, Hibernate etc –View- integrated with JSP, JSTL, JSF, Jakarta Velocity, Templates, PDF, XSLT etc. –Controller- based on many standard technologies like Java Filters, Java Beans, ResourceBundles, XML etc.

Page 7: Struts

What is Struts2 Framework

www.rajkrrsingh.blogspot.com

Page 8: Struts

Struts 2 Architecture

www.rajkrrsingh.blogspot.com

Page 9: Struts

Struts 2 Architecture

www.rajkrrsingh.blogspot.com

Page 10: Struts

The Core Components

www.rajkrrsingh.blogspot.com

Controller : Filter dispatcher, by which all the requests to the applications gets filtered.

Interceptors : called after filters, apply common functionalities like validation, conversion etc before Action methods.

Action : has execute methods, usually storing and/or retrieving information from a database for the view,i.e the jsp files.

Result : Render the output as a view component i.e jsp file.

Page 11: Struts

Request Cycle:

www.rajkrrsingh.blogspot.com

1.Container pass request to filter chain. 2.Chain includes the (optional) ActionContextCleanUp filter (useful when integrating technologies such as SiteMesh Plugin) 3.Required FilterDispatcher is called and consults with ActionMapper to determine if the request should invoke an action. 4.If Action should be invoked, the FilterDispatcher delegates control to the ActionProxy. 5.The ActionProxy consults the framework Configuration Files manager (initialized from the struts.xml file). 6.Next, the ActionProxy creates an ActionInvocation, which is responsible for the command pattern implementation. 7.This includes invoking any Interceptors in advance of invoking the Action itself.

Page 12: Struts

Response Cycle:

www.rajkrrsingh.blogspot.com

1. When Action returns, the ActionInvocation=>looking up=>Action result code mapped in struts.xml. 2.The result is then executed, which often involves a template written in JSP to be rendered. 3.While rendering, the templates can use the Struts Tags provided by the framework. 4.Interceptors are executed again in reverse order. 5.If the ActionContextCleanUp filter is present, the FilterDispatcher will not clean up the ThreadLocal ActionContext. (One can use ThreadLocal to keep certain objects/values available throught the thread execution.) 6.If the ActionContextCleanUp filter is not present, the FilterDispatcher will cleanup all ThreadLocals.

Page 13: Struts

Why Struts 2 - Features

www.rajkrrsingh.blogspot.com

Simplified Design–Classes are based on interfaces–Action classes are simple POJOs

Simplified Actions–Any java class with execute() method can be used as an Action class.–Inversion of Control is introduced while developing the action classes•(actions to be neutral to the underlying framework .)

Page 14: Struts

Why Struts 2 - Features

www.rajkrrsingh.blogspot.com

No more Action Forms Annotations introduced Stateful Checkboxes Easy Spring integration Easy plugin AJAX support Better Tag features Both JSP and FreeMarker tags are fully supported.

Page 15: Struts

Difference in Struts 1 and Struts 2

www.rajkrrsingh.blogspot.com

Page 16: Struts

Difference in Struts 1 and Struts 2

www.rajkrrsingh.blogspot.com

Page 17: Struts

Difference in Struts 1 and Struts 2

www.rajkrrsingh.blogspot.com

Page 18: Struts

Structure of URL

www.rajkrrsingh.blogspot.com

Page 19: Struts

Struts.xml

www.rajkrrsingh.blogspot.com

Core configuration file for framework. Can contain multiple package.

<struts> <package name=“base” extends=“struts-default” namespace=“/”> <action name=“. . . .”> <result>. . . . . . . </action> </package> <include file=“hr.xml”/> </struts>

Page 20: Struts

Struts.xml

www.rajkrrsingh.blogspot.com

Page 21: Struts

Struts-default.xml

www.rajkrrsingh.blogspot.com

Shipped in struts2-core.x.x.jar Most of your packages will extends Directly / Indirectly Contains about everything you need. Package from inheritance hierarchy. The Key section are package result-Type interceptors/stack

Page 22: Struts

Interceptors

www.rajkrrsingh.blogspot.com

Responsible for most of the processing done by the framework. Handle most of the fundamental preprocessing and post-processing tasks. Instead of invoking an action directly, this sits between the controller and the action. The invocation of an action is a layered process that always includes the execution of a stack of interceptors prior to and after the actual execution of the action itself.

Page 23: Struts

Struts2 tags

www.rajkrrsingh.blogspot.com

Struts2 support following types of tags A.UI Tags

i.Form Tags ii.Non Form UI Tags iii.Ajax Tags

B.Generic Tags i.Control Tags ii.Data Tags

Page 24: Struts

Struts2 tags

www.rajkrrsingh.blogspot.com

A.UI Tags

render the HTML form and non-form componnets. <textfield> <password> <hidden> <textarea> <radio> <checkbox> <checkboxlist> <select> <combobox> <head> <file>

Page 25: Struts

OGNL

www.rajkrrsingh.blogspot.com

•Powerful expression language that is used to reference and manipulate data on the ValueStack.•Helps in data transfer and type conversion.•Very similar to the JSP Expression Language.•Based on a context and Struts builds an ActionContext map for use with OGNL.•The ActionContext map consists of the following:•application - application scoped variables•session - session scoped variables•root / value stack - all your action variables are stored here•request - request scoped variables•parameters - request parameters•atributes - the attributes stored in page, request, session and application scope

Page 26: Struts

Action/ValueStack/OGNL

www.rajkrrsingh.blogspot.com

Page 27: Struts

QA

www.rajkrrsingh.blogspot.com


Recommended