SlideShare une entreprise Scribd logo
1  sur  27
Struts Workshop




   Presented By
  Rajkumar Singh




             www.rajkrrsingh.blogspot.com
Agenda

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




                                      www.rajkrrsingh.blogspot.com
MVC




      www.rajkrrsingh.blogspot.com
What is Struts2 Framework

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




                                       www.rajkrrsingh.blogspot.com
What is Struts2 Framework


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




                                     www.rajkrrsingh.blogspot.com
What is Struts2 Framework

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.




                                      www.rajkrrsingh.blogspot.com
What is Struts2 Framework




                       www.rajkrrsingh.blogspot.com
Struts 2 Architecture




                        www.rajkrrsingh.blogspot.com
Struts 2 Architecture




                        www.rajkrrsingh.blogspot.com
The Core Components

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.




                                           www.rajkrrsingh.blogspot.com
Request Cycle:
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.



                                          www.rajkrrsingh.blogspot.com
Response Cycle:
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.




                                             www.rajkrrsingh.blogspot.com
Why Struts 2 - Features

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




                                           www.rajkrrsingh.blogspot.com
Why Struts 2 - Features


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




                                         www.rajkrrsingh.blogspot.com
Difference in Struts 1 and Struts 2




                          www.rajkrrsingh.blogspot.com
Difference in Struts 1 and Struts 2




                          www.rajkrrsingh.blogspot.com
Difference in Struts 1 and Struts 2




                          www.rajkrrsingh.blogspot.com
Structure of URL




                   www.rajkrrsingh.blogspot.com
Struts.xml


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




                                       www.rajkrrsingh.blogspot.com
Struts.xml




             www.rajkrrsingh.blogspot.com
Struts-default.xml


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




                                             www.rajkrrsingh.blogspot.com
Interceptors

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




                                               www.rajkrrsingh.blogspot.com
Struts2 tags

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




                                          www.rajkrrsingh.blogspot.com
Struts2 tags


  A.UI Tags

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

                                     www.rajkrrsingh.blogspot.com
OGNL
•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




                                          www.rajkrrsingh.blogspot.com
Action/ValueStack/OGNL




                         www.rajkrrsingh.blogspot.com
QA




     www.rajkrrsingh.blogspot.com

Contenu connexe

Tendances

Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
elliando dias
 
Strut2-Spring-Hibernate
Strut2-Spring-HibernateStrut2-Spring-Hibernate
Strut2-Spring-Hibernate
Jay Shah
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
elliando dias
 
What is the difference between struts 1 vs struts 2
What is the difference between struts 1 vs struts 2What is the difference between struts 1 vs struts 2
What is the difference between struts 1 vs struts 2
Santosh Singh Paliwal
 
JPA lifecycle events practice
JPA lifecycle events practiceJPA lifecycle events practice
JPA lifecycle events practice
Guo Albert
 

Tendances (20)

Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
 
Struts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web ApplicationsStruts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web Applications
 
Introduction to struts
Introduction to strutsIntroduction to struts
Introduction to struts
 
Struts 1
Struts 1Struts 1
Struts 1
 
Struts2
Struts2Struts2
Struts2
 
Struts framework
Struts frameworkStruts framework
Struts framework
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
 
Struts
StrutsStruts
Struts
 
Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 Advance
 
Struts 2
Struts 2Struts 2
Struts 2
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
 
Struts2 notes
Struts2 notesStruts2 notes
Struts2 notes
 
Strut2-Spring-Hibernate
Strut2-Spring-HibernateStrut2-Spring-Hibernate
Strut2-Spring-Hibernate
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
 
Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 
What is the difference between struts 1 vs struts 2
What is the difference between struts 1 vs struts 2What is the difference between struts 1 vs struts 2
What is the difference between struts 1 vs struts 2
 
JPA lifecycle events practice
JPA lifecycle events practiceJPA lifecycle events practice
JPA lifecycle events practice
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2Migrating from Struts 1 to Struts 2
Migrating from Struts 1 to Struts 2
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
 

En vedette

Introduction to Java Enterprise Edition
Introduction to Java Enterprise EditionIntroduction to Java Enterprise Edition
Introduction to Java Enterprise Edition
Abdalla Mahmoud
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
Brett Meyer
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 

En vedette (20)

Introduction to Java Enterprise Edition
Introduction to Java Enterprise EditionIntroduction to Java Enterprise Edition
Introduction to Java Enterprise Edition
 
Java Enterprise Edition
Java Enterprise EditionJava Enterprise Edition
Java Enterprise Edition
 
TIEIT Systems - Trainings (Java JEE Spring training)
TIEIT Systems - Trainings (Java JEE Spring training)TIEIT Systems - Trainings (Java JEE Spring training)
TIEIT Systems - Trainings (Java JEE Spring training)
 
Struts Overview
Struts OverviewStruts Overview
Struts Overview
 
Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
 
Struts2
Struts2Struts2
Struts2
 
JAVA EE training from 3rd-oct-2015
JAVA EE training from 3rd-oct-2015JAVA EE training from 3rd-oct-2015
JAVA EE training from 3rd-oct-2015
 
Struts(mrsurwar) ppt
Struts(mrsurwar) pptStruts(mrsurwar) ppt
Struts(mrsurwar) ppt
 
Spring By Example One Day Workshop
Spring By Example One Day WorkshopSpring By Example One Day Workshop
Spring By Example One Day Workshop
 
A PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATEA PRESENTATION ON STRUTS & HIBERNATE
A PRESENTATION ON STRUTS & HIBERNATE
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
Hibernate architecture
Hibernate architectureHibernate architecture
Hibernate architecture
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Designing JEE Application Structure
Designing JEE Application StructureDesigning JEE Application Structure
Designing JEE Application Structure
 
Why do I hate Hibernate?
Why do I hate Hibernate?Why do I hate Hibernate?
Why do I hate Hibernate?
 
JEE Programming - 01 Introduction
JEE Programming - 01 IntroductionJEE Programming - 01 Introduction
JEE Programming - 01 Introduction
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 
ORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate OverviewORM, JPA, & Hibernate Overview
ORM, JPA, & Hibernate Overview
 
Creating modern java web applications based on struts2 and angularjs
Creating modern java web applications based on struts2 and angularjsCreating modern java web applications based on struts2 and angularjs
Creating modern java web applications based on struts2 and angularjs
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 

Similaire à Struts

Krazykoder struts2 intro
Krazykoder struts2 introKrazykoder struts2 intro
Krazykoder struts2 intro
Krazy Koder
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questions
surendray
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
yesprakash
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
Long Nguyen
 

Similaire à Struts (20)

Struts
StrutsStruts
Struts
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questions
 
Krazykoder struts2 intro
Krazykoder struts2 introKrazykoder struts2 intro
Krazykoder struts2 intro
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questions
 
Struts 2 – Interceptors
Struts 2 – InterceptorsStruts 2 – Interceptors
Struts 2 – Interceptors
 
Struts
StrutsStruts
Struts
 
Apachecon 2002 Struts
Apachecon 2002 StrutsApachecon 2002 Struts
Apachecon 2002 Struts
 
Struts Basics
Struts BasicsStruts Basics
Struts Basics
 
Struts by l n rao
Struts by l n raoStruts by l n rao
Struts by l n rao
 
Struts2 in a nutshell
Struts2 in a nutshellStruts2 in a nutshell
Struts2 in a nutshell
 
Struts course material
Struts course materialStruts course material
Struts course material
 
Ibm
IbmIbm
Ibm
 
Lecture 05 web_applicationframeworks
Lecture 05 web_applicationframeworksLecture 05 web_applicationframeworks
Lecture 05 web_applicationframeworks
 
Struts2-Spring=Hibernate
Struts2-Spring=HibernateStruts2-Spring=Hibernate
Struts2-Spring=Hibernate
 
Struts2.0basic
Struts2.0basicStruts2.0basic
Struts2.0basic
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Struts notes
Struts notesStruts notes
Struts notes
 

Struts

  • 1. Struts Workshop Presented By Rajkumar Singh www.rajkrrsingh.blogspot.com
  • 2. Agenda 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 www.rajkrrsingh.blogspot.com
  • 3. MVC www.rajkrrsingh.blogspot.com
  • 4. What is Struts2 Framework A framework tries to automate the common tasks and provides a platform for the users to build applications quickly. www.rajkrrsingh.blogspot.com
  • 5. What is Struts2 Framework Struts 2 is a very well-designed and flexible. An integration of Struts 1 with OpenSymphony Web Works Framework www.rajkrrsingh.blogspot.com
  • 6. What is Struts2 Framework 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. www.rajkrrsingh.blogspot.com
  • 7. What is Struts2 Framework www.rajkrrsingh.blogspot.com
  • 8. Struts 2 Architecture www.rajkrrsingh.blogspot.com
  • 9. Struts 2 Architecture www.rajkrrsingh.blogspot.com
  • 10. The Core Components 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. www.rajkrrsingh.blogspot.com
  • 11. Request Cycle: 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. www.rajkrrsingh.blogspot.com
  • 12. Response Cycle: 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. www.rajkrrsingh.blogspot.com
  • 13. Why Struts 2 - Features 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 .) www.rajkrrsingh.blogspot.com
  • 14. Why Struts 2 - Features 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. www.rajkrrsingh.blogspot.com
  • 15. Difference in Struts 1 and Struts 2 www.rajkrrsingh.blogspot.com
  • 16. Difference in Struts 1 and Struts 2 www.rajkrrsingh.blogspot.com
  • 17. Difference in Struts 1 and Struts 2 www.rajkrrsingh.blogspot.com
  • 18. Structure of URL www.rajkrrsingh.blogspot.com
  • 19. Struts.xml 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> www.rajkrrsingh.blogspot.com
  • 20. Struts.xml www.rajkrrsingh.blogspot.com
  • 21. Struts-default.xml 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 www.rajkrrsingh.blogspot.com
  • 22. Interceptors 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. www.rajkrrsingh.blogspot.com
  • 23. Struts2 tags 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 www.rajkrrsingh.blogspot.com
  • 24. Struts2 tags A.UI Tags render the HTML form and non-form componnets. <textfield> <password> <hidden> <textarea> <radio> <checkbox> <checkboxlist> <select> <combobox> <head> <file> www.rajkrrsingh.blogspot.com
  • 25. OGNL •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 www.rajkrrsingh.blogspot.com
  • 26. Action/ValueStack/OGNL www.rajkrrsingh.blogspot.com
  • 27. QA www.rajkrrsingh.blogspot.com