SlideShare a Scribd company logo
Java Hibernate Training
Introducing Struts Framework
Page 1Classification: Restricted
Agenda
• Introduction to Struts Framework
• Features
• Evolution
• Struts Demo
• Declarative validation
• Architecture
• Validators
• Interceptors
Page 2Classification: Restricted
Struts framework
• The struts 2 framework is used to develop MVC-based
web application.
• The struts framework was initially created by Craig
McClanahan and donated to Apache Foundation in May,
2000 and Struts 1.0 was released in June 2001.
• Craig R. McClanahan is a programmer and original
author of the Apache Struts framework for building web
applications. He was part of the expert group that
defined the servlet 2.2, 2.3 and JSP 1.1, 1.2
specifications. He is also the architect of Tomcat's servlet
container Catalina.
Page 3Classification: Restricted
Struts 2 Framework
• The Struts 2 framework is used to develop MVC (Model View Controller)
based web applications. Struts 2 is the combination of webwork
framework of opensymphony and struts 1.
struts2 = webwork + struts1
Page 4Classification: Restricted
Struts 2 Features
• Configurable MVC components
• POJO based actions
• AJAX support
• Integration support – with Hibernate, Spring etc
• Various Result Types – JSP, Freemarker, Velocity etc
• Various Tag support
• Theme and Template support
Page 5Classification: Restricted
Web Application Architecture - Evolution
• Model 1 Architecture
pag
e 5
• Navigation control is decentralized
• Time Consuming
• Hard to extend
Page 6Classification: Restricted
Web Application Architecture - Evolution
• Model 2 Architecture
pag
e 6
• Navigation control is centralized Now only controller contains the logic to determine the next
page.
• Easy to maintain, extend and test
• Better separation of concerns
• (SOLID principles: OOP: Single Responsibility Principle)
Page 7Classification: Restricted
Struts… building your first app
• Struts – Configuring in Eclipse demo
Page 8Classification: Restricted
• JSP: Server Page technology… like ASP, BSP…
• Page is dynamically built on the server…
• Presentation logic goes into the server.
• Limitation:
• As number of clients increases, the server has more work to do. (Controller
logic + Presentation Logic)
• If your web app is responsive/adaptive, it has much more work to do on the
presentation logic.. It has to check the form factor of the device that is
trying to access the web page…
• Solution:
• Move the presentation logic to the client… JS libraries (Angular) + CSS (LESS,
SASS)..
• RESTful architecture.
Page 9Classification: Restricted
Struts demo
• Login Page
• Validation Example
Page 10Classification: Restricted
Declarative validation
//<ActionClassName>-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
Use appropriate DTD here!!
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="username">
<field-validator type="requiredstring">
<message>Name can't be blank</message>
</field-validator>
</field>
Page 11Classification: Restricted
Struts 2 Architecture
Page 12Classification: Restricted
Struts ready-to-use Validators
• requiredstring validator
• stringlength validator
• email validator
• date validator
• int validator
• double validator
• url validator
• regex validator
Page 13Classification: Restricted
Struts 2 interceptors
• Interceptors are conceptually the same as servlet filters or the JDKs Proxy
class. Interceptors allow for crosscutting functionality to be implemented
separately from the action as well as the framework. You can achieve the
following using interceptors:
• Providing preprocessing logic before the action is called.
• Providing postprocessing logic after the action is called.
• Catching exceptions so that alternate processing can be performed.
Page 14Classification: Restricted
17-08-2018 14
Interceptors
 Can execute code before and after execution
 Are thread-safe
 Can be used for
 Validation
 Pre populating fields
 Double-submit prevention
 Session control
 Authentication
 Type conversion
Page 15Classification: Restricted
Some Struts 2 Interceptors
alias Allows parameters to have different name aliases across requests.
checkbox Assists in managing check boxes by adding a parameter value of
false for check boxes that are not checked.
conversionError Places error information from converting strings to parameter
types into the action's field errors.
createSession Automatically creates an HTTP session if one does not already
exist.
debugging Provides several different debugging screens to the developer.
execAndWait Sends the user to an intermediary waiting page while the action
executes in the background.
exception Maps exceptions that are thrown from an action to a result,
allowing automatic exception handling via redirection.
fileUpload Facilitates easy file uploading.
i18n Keeps track of the selected locale during a user's session.
logger Provides simple logging by outputting the name of the action being
executed.
Page 16Classification: Restricted
Using interceptors
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">
<action name="hello"
class="com.xyz.HelloWorldAction"
method="execute">
<interceptor-ref name="params"/>
<interceptor-ref name="timer" />
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
Page 17Classification: Restricted
Topics to be covered in next session
• Struts 2
• Struts Action Class
• Validation
• Control Tags
• Data Tags
Page 18Classification: Restricted
Thank you!

More Related Content

What's hot (16)

PPSX
JSP - Part 1
Hitesh-Java
 
PPTX
Session 38 - Core Java (New Features) - Part 1
PawanMM
 
PPSX
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
PPSX
Spring - Part 3 - AOP
Hitesh-Java
 
PPSX
JSP - Part 2 (Final)
Hitesh-Java
 
PPSX
Java IO, Serialization
Hitesh-Java
 
PDF
Hibernate Interview Questions
Syed Shahul
 
PPTX
Spring & hibernate
Santosh Kumar Kar
 
DOC
24 collections framework interview questions
Arun Vasanth
 
PDF
Hibernate Presentation
guest11106b
 
PPSX
Hibernate - Part 1
Hitesh-Java
 
PPTX
Next stop: Spring 4
Oleg Tsal-Tsalko
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PDF
Spring 4 Web App
Rossen Stoyanchev
 
PPTX
Spring mvc
Harshit Choudhary
 
PDF
Bea weblogic job_interview_preparation_guide
Pankaj Singh
 
JSP - Part 1
Hitesh-Java
 
Session 38 - Core Java (New Features) - Part 1
PawanMM
 
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
Spring - Part 3 - AOP
Hitesh-Java
 
JSP - Part 2 (Final)
Hitesh-Java
 
Java IO, Serialization
Hitesh-Java
 
Hibernate Interview Questions
Syed Shahul
 
Spring & hibernate
Santosh Kumar Kar
 
24 collections framework interview questions
Arun Vasanth
 
Hibernate Presentation
guest11106b
 
Hibernate - Part 1
Hitesh-Java
 
Next stop: Spring 4
Oleg Tsal-Tsalko
 
Spring Framework - Core
Dzmitry Naskou
 
Spring 4 Web App
Rossen Stoyanchev
 
Spring mvc
Harshit Choudhary
 
Bea weblogic job_interview_preparation_guide
Pankaj Singh
 

Similar to Struts 2 - Introduction (20)

PPTX
Struts Interceptors
Onkar Deshpande
 
PDF
Struts 2 In Action 1st Edition Don Brown Chad Michael Davis Scott Stanlick
akanalettsxz
 
PPT
Struts2.x
Sandeep Rawat
 
PPTX
struts unit best pdf for struts java.pptx
ozakamal8
 
PPTX
Struts
Ishita Gandhi
 
PPTX
Struts 2 – Interceptors
Ducat India
 
PPTX
Skillwise Struts.x
Skillwise Group
 
PPT
Struts2
shankar_b7
 
PPT
Struts2
Manav Prasad
 
PPTX
Struts
Rajkumar Singh
 
PPT
strut2
sudarshan9
 
PPT
Strut2-Spring-Hibernate
Jay Shah
 
DOCX
What is the difference between struts 1 vs struts 2
Santosh Singh Paliwal
 
PPT
Struts2.0basic
­Avishek A
 
PPT
Struts2-Spring=Hibernate
Jay Shah
 
PPT
Struts2 course chapter 1: Evolution of Web Applications
JavaEE Trainers
 
PPTX
Introduction to Struts 2
Collaboration Technologies
 
PPTX
A PRESENTATION ON STRUTS & HIBERNATE
Tushar Choudhary
 
Struts Interceptors
Onkar Deshpande
 
Struts 2 In Action 1st Edition Don Brown Chad Michael Davis Scott Stanlick
akanalettsxz
 
Struts2.x
Sandeep Rawat
 
struts unit best pdf for struts java.pptx
ozakamal8
 
Struts 2 – Interceptors
Ducat India
 
Skillwise Struts.x
Skillwise Group
 
Struts2
shankar_b7
 
Struts2
Manav Prasad
 
strut2
sudarshan9
 
Strut2-Spring-Hibernate
Jay Shah
 
What is the difference between struts 1 vs struts 2
Santosh Singh Paliwal
 
Struts2.0basic
­Avishek A
 
Struts2-Spring=Hibernate
Jay Shah
 
Struts2 course chapter 1: Evolution of Web Applications
JavaEE Trainers
 
Introduction to Struts 2
Collaboration Technologies
 
A PRESENTATION ON STRUTS & HIBERNATE
Tushar Choudhary
 
Ad

More from Hitesh-Java (20)

PPSX
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Hitesh-Java
 
PPSX
JDBC Part - 2
Hitesh-Java
 
PPSX
JDBC
Hitesh-Java
 
PPSX
Inner Classes
Hitesh-Java
 
PPSX
Collections - Maps
Hitesh-Java
 
PPSX
Review Session - Part -2
Hitesh-Java
 
PPSX
Review Session and Attending Java Interviews
Hitesh-Java
 
PPSX
Collections - Lists, Sets
Hitesh-Java
 
PPSX
Collections - Sorting, Comparing Basics
Hitesh-Java
 
PPSX
Collections - Array List
Hitesh-Java
 
PPSX
Object Class
Hitesh-Java
 
PPSX
Exception Handling - Continued
Hitesh-Java
 
PPSX
Exception Handling - Part 1
Hitesh-Java
 
PPSX
OOPs with Java - Packaging and Access Modifiers
Hitesh-Java
 
PPSX
OOP with Java - Abstract Classes and Interfaces
Hitesh-Java
 
PPSX
OOP with Java - Part 3
Hitesh-Java
 
PPSX
OOP with Java - Continued
Hitesh-Java
 
PPSX
Intro to Object Oriented Programming with Java
Hitesh-Java
 
PPSX
Practice Session
Hitesh-Java
 
PPSX
Strings in Java
Hitesh-Java
 
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Hitesh-Java
 
JDBC Part - 2
Hitesh-Java
 
Inner Classes
Hitesh-Java
 
Collections - Maps
Hitesh-Java
 
Review Session - Part -2
Hitesh-Java
 
Review Session and Attending Java Interviews
Hitesh-Java
 
Collections - Lists, Sets
Hitesh-Java
 
Collections - Sorting, Comparing Basics
Hitesh-Java
 
Collections - Array List
Hitesh-Java
 
Object Class
Hitesh-Java
 
Exception Handling - Continued
Hitesh-Java
 
Exception Handling - Part 1
Hitesh-Java
 
OOPs with Java - Packaging and Access Modifiers
Hitesh-Java
 
OOP with Java - Abstract Classes and Interfaces
Hitesh-Java
 
OOP with Java - Part 3
Hitesh-Java
 
OOP with Java - Continued
Hitesh-Java
 
Intro to Object Oriented Programming with Java
Hitesh-Java
 
Practice Session
Hitesh-Java
 
Strings in Java
Hitesh-Java
 
Ad

Recently uploaded (20)

PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PPTX
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 

Struts 2 - Introduction

  • 2. Page 1Classification: Restricted Agenda • Introduction to Struts Framework • Features • Evolution • Struts Demo • Declarative validation • Architecture • Validators • Interceptors
  • 3. Page 2Classification: Restricted Struts framework • The struts 2 framework is used to develop MVC-based web application. • The struts framework was initially created by Craig McClanahan and donated to Apache Foundation in May, 2000 and Struts 1.0 was released in June 2001. • Craig R. McClanahan is a programmer and original author of the Apache Struts framework for building web applications. He was part of the expert group that defined the servlet 2.2, 2.3 and JSP 1.1, 1.2 specifications. He is also the architect of Tomcat's servlet container Catalina.
  • 4. Page 3Classification: Restricted Struts 2 Framework • The Struts 2 framework is used to develop MVC (Model View Controller) based web applications. Struts 2 is the combination of webwork framework of opensymphony and struts 1. struts2 = webwork + struts1
  • 5. Page 4Classification: Restricted Struts 2 Features • Configurable MVC components • POJO based actions • AJAX support • Integration support – with Hibernate, Spring etc • Various Result Types – JSP, Freemarker, Velocity etc • Various Tag support • Theme and Template support
  • 6. Page 5Classification: Restricted Web Application Architecture - Evolution • Model 1 Architecture pag e 5 • Navigation control is decentralized • Time Consuming • Hard to extend
  • 7. Page 6Classification: Restricted Web Application Architecture - Evolution • Model 2 Architecture pag e 6 • Navigation control is centralized Now only controller contains the logic to determine the next page. • Easy to maintain, extend and test • Better separation of concerns • (SOLID principles: OOP: Single Responsibility Principle)
  • 8. Page 7Classification: Restricted Struts… building your first app • Struts – Configuring in Eclipse demo
  • 9. Page 8Classification: Restricted • JSP: Server Page technology… like ASP, BSP… • Page is dynamically built on the server… • Presentation logic goes into the server. • Limitation: • As number of clients increases, the server has more work to do. (Controller logic + Presentation Logic) • If your web app is responsive/adaptive, it has much more work to do on the presentation logic.. It has to check the form factor of the device that is trying to access the web page… • Solution: • Move the presentation logic to the client… JS libraries (Angular) + CSS (LESS, SASS).. • RESTful architecture.
  • 10. Page 9Classification: Restricted Struts demo • Login Page • Validation Example
  • 11. Page 10Classification: Restricted Declarative validation //<ActionClassName>-validation.xml <?xml version="1.0" encoding="UTF-8"?> Use appropriate DTD here!! <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> <validators> <field name="username"> <field-validator type="requiredstring"> <message>Name can't be blank</message> </field-validator> </field>
  • 13. Page 12Classification: Restricted Struts ready-to-use Validators • requiredstring validator • stringlength validator • email validator • date validator • int validator • double validator • url validator • regex validator
  • 14. Page 13Classification: Restricted Struts 2 interceptors • Interceptors are conceptually the same as servlet filters or the JDKs Proxy class. Interceptors allow for crosscutting functionality to be implemented separately from the action as well as the framework. You can achieve the following using interceptors: • Providing preprocessing logic before the action is called. • Providing postprocessing logic after the action is called. • Catching exceptions so that alternate processing can be performed.
  • 15. Page 14Classification: Restricted 17-08-2018 14 Interceptors  Can execute code before and after execution  Are thread-safe  Can be used for  Validation  Pre populating fields  Double-submit prevention  Session control  Authentication  Type conversion
  • 16. Page 15Classification: Restricted Some Struts 2 Interceptors alias Allows parameters to have different name aliases across requests. checkbox Assists in managing check boxes by adding a parameter value of false for check boxes that are not checked. conversionError Places error information from converting strings to parameter types into the action's field errors. createSession Automatically creates an HTTP session if one does not already exist. debugging Provides several different debugging screens to the developer. execAndWait Sends the user to an intermediary waiting page while the action executes in the background. exception Maps exceptions that are thrown from an action to a result, allowing automatic exception handling via redirection. fileUpload Facilitates easy file uploading. i18n Keeps track of the selected locale during a user's session. logger Provides simple logging by outputting the name of the action being executed.
  • 17. Page 16Classification: Restricted Using interceptors <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="helloworld" extends="struts-default"> <action name="hello" class="com.xyz.HelloWorldAction" method="execute"> <interceptor-ref name="params"/> <interceptor-ref name="timer" /> <result name="success">/HelloWorld.jsp</result> </action> </package> </struts>
  • 18. Page 17Classification: Restricted Topics to be covered in next session • Struts 2 • Struts Action Class • Validation • Control Tags • Data Tags