SlideShare a Scribd company logo
1 of 25
STRUTS 
INTERCEPTORS 
© Onkar Deshpande
Agenda 
 What is Apache Struts 2.x ? 
 Features of Apache Struts 2.x 
 How Struts 2.x works ? 
 Struts 2.x Architecture Overview 
 Struts 2.0 MVC Components 
 Request – Response Pipeline 
 Interceptors 
 Need of Interceptors 
 Understanding the Difference Between Filters & Interceptors 
 Configuring Interceptor 
 Frameworks(In-built) Interceptors 
 Custom Inceptors 
 Disadvantages of Struts 
2 
© Onkar Deshpande
What is Apache Struts 2.x? 
 Apache Struts 2 is an Open Source, elegant & 
extensible framework for creating enterprise-ready 
Java web applications 
 The framework is designed to streamline the full 
development cycle, from building, to deploying, to 
maintaining applications over time 
 It is Action Based Framework 
 Cerate's web application using MVC 2 
architecture 
 Apache Struts offer two major version 
 Struts 1.x 
 Struts 2.x 
 Struts 2 = WebWork + Struts 
3 
© Onkar Deshpande
Features of Struts 2.x 
 MVC Framework 
 Struts provides a unified framework for deploying 
servlet and JSP applications that use the MVC 
architecture 
 A Set of JSP Custom Tag Libraries 
 Struts provides custom tag libraries for outputting 
bean properties, generating HTML forms, iterating 
over various types of data structures, and 
conditionally outputting HTML 
 A Collection of Utilities 
 Struts provides utility classes to handle many of the 
most common tasks in Web application development 
4 
© Onkar Deshpande
Features of Struts 2.x 
continued… 
 Centralized file-based configuration 
 Rather then hard-coding information into Java 
programs, many Struts values are represented in 
XML or property files. This loose coupling means 
that many changes can be made without 
modifying or recompiling Java code, and that 
wholesale changes can be made by editing a 
single file. This approach also lets Java and Web 
developers focus on their specific tasks 
(implementing business logic, presenting certain 
values to clients, etc.) without needing to know 
about the overall system layout 
5 
© Onkar Deshpande
Features of Struts 2.x 
continued… 
 HTML tags 
Apache Struts provides a set of 
custom JSP tags to create HTML 
forms that are associated with 
JavaBeans components. This 
bean/form association serves two 
useful purposes: 
It lets you get initial form-field values from 
Java objects 
It lets you redisplay forms with some or all 
previously entered values intact 
6 
© Onkar Deshpande
Features of Struts 2.x 
continued… 
 Form field validation 
 Apache Struts has builtin capabilities for checking 
that form values are in the required format. If 
values are missing or in an improper format, the 
form can be automatically redisplayed with error 
messages and with the previously entered values 
maintained 
 This validation can be performed on the server (in 
Java), or both on the server and on the client (in 
JavaScript) 
 Consistent approach 
 Struts encourages consistent use of MVC 
throughout your app 
7 
© Onkar Deshpande
8 How Struts 2.x works? 
© Onkar Deshpande
Struts 2.x Architecture Overview 
9 
© Onkar Deshpande
Struts 2.x Architecture Overview 
10 
© Onkar Deshpande
Struts 2.0 MVC Components 
Core components of the framework 
 Controller:- 
 Filter Dispatcher:- 
 First component that start processing that is why this type of 
MVC is called front controller MVC 
 Looks at the request and apply the appropriate action. 
 Struts framework handles all of the controller work. 
 Its configured in web.xml 
 Interceptors:- 
 Can execute code before and after an Action is executed. 
 They can be configured per action basis. 
 Can be used for data validation, file upload, double submit 
guards. 
11 
© Onkar Deshpande
Struts 2.0 MVC Components 
contd. 
 Model:- 
 Implemented by action class 
 For model you can use any data access 
technologies like JDBC,EJB,Hibernate 
 View 
 Its your result part. It can be JSP,JSTL,JSF etc. 
 Presentation part of the MVC 
12 
© Onkar Deshpande
Request – Response Pipeline 
13 
© Onkar Deshpande
Need of Interceptors 
 Many Actions share common concerns 
 Some Actions need input validated 
 The framework makes it easy to share 
solutions to these concerns using an 
"Interceptor" strategy 
 Interceptors can execute code before and after 
an Action is invoked 
 Interceptors "set the stage" for the Action 
classes 
14 
© Onkar Deshpande
15 Interceptor Looks like Filters 
© Onkar Deshpande
Understanding the Difference 
Filters Interceptors 
Based on Servlet Specification Based on Struts2. 
Executes on the pattern matches on the 
request. 
Executes for all the request qualifies for 
a front controller( A Servlet filter ).And 
can be configured to execute additional 
interceptor for a particular action 
execution. 
Not configurable method calls Methods in the Interceptors can be 
configured whether to execute or not by 
means of excludemethods or 
includeMethods 
A Servlet Filter is used in the web layer 
only, you can’t use it outside of a web 
context. 
Interceptors can be used anywhere. 
That’s the main difference. 
for authentication of web pages you 
would use a servlet filter 
For security stuff in your business layer 
or logging/bugtracing (a.k.a. 
16 
© Onkar Deshpande
Understanding Interceptors 
17 
© Onkar Deshpande
Understanding Interceptors 
Continued… 
18 
© Onkar Deshpande
Configuring Interceptor 
 <action name="login" 
class=“pack.className"> <interceptor-ref 
name="timer"/> 
<interceptor-ref name="logger"/> 
<result name="input">login.jsp</result> 
<result name="success“ 
type="redirectAction">home</result> 
</action> 
19 
© Onkar Deshpande
Frameworks(In-built) 
Interceptors 
 ParametersInterceptor 
 It sets request parameter into the action 
 This interceptor gets all parameters from request 
and sets them on the value stack, typically 
resulting in the values submitted in a form request 
being applied to an action in the value stack 
 AliasInterceptor 
 Converts similar parameters that may be named 
differently between requests 
20 
© Onkar Deshpande
Frameworks(In-built) 
Interceptors cont.. 
 ServletConfigInterceptor 
 An interceptor which sets action properties based 
on the interfaces an action implements 
 For example, if the action implements 
ServletRequestAware interface then setting of 
HttpServletRequest is done by this interceptor 
 This interceptor is designed to set all properties 
an action needs if it's aware of servlet 
parameters, the servlet context, the session, etc 
21 
© Onkar Deshpande
Frameworks(In-built) 
Interceptors cont.. 
 WorkflowInterceptor 
 An interceptor that makes sure there are not validation 
errors before allowing the interceptor chain to continue 
 This interceptor does not perform any validation 
 ValidationInterceptor 
 This interceptor runs the action through the standard 
validation framework 
 It checks the action against any validation rules (found in 
files such as ActionClass-validation.xml) 
 The workflow of the action request does not change due to 
this interceptor 
 Rather, this interceptor is often used in conjuction with 
the workflow interceptor 
22 
© Onkar Deshpande
Disadvantages of Struts 
 Bigger learning curve 
 To use MVC with the standard RequestDispatcher, you need to 
be comfortable with the standard JSP and servlet APIs. To use 
MVC with Struts, you have to be comfortable with the standard 
JSP and servlet APIs and a large and elaborate framework that is 
almost equal in size to the core system. This drawback is 
especially significant with smaller projects, near-term deadlines, 
and less experienced developers; you could spend as much time 
learning Struts as building your actual system 
 Poor documentation 
 Compared to the standard servlet and JSP APIs, Struts has 
fewer online resources, and many first-time users find the online 
Apache documentation confusing and poorly organized. There 
are also fewer books on Apache Struts than on standard servlets 
and JSP 
23 
© Onkar Deshpande
Disadvantages of Struts 
 Less transparent 
 With Struts applications, there is a lot more going on 
behind the scenes than with normal Java-based Web 
applications. As a result, Struts applications are: 
 Harder to understand 
 Harder to benchmark and optimize 
 Rigid approach 
 The flip side of the benefit that Struts encourages a 
consistent approach to MVC is that Struts makes it 
difficult (but by no means impossible) to use other 
approaches 
24 
© Onkar Deshpande
25 Thank You 
© Onkar Deshpande

More Related Content

What's hot

Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
Next.js Introduction
Next.js IntroductionNext.js Introduction
Next.js IntroductionSaray Chak
 
Servlet & JSP 教學手冊第二版 - 第 1 章:簡介Web應用程式
Servlet & JSP 教學手冊第二版 - 第 1 章:簡介Web應用程式Servlet & JSP 教學手冊第二版 - 第 1 章:簡介Web應用程式
Servlet & JSP 教學手冊第二版 - 第 1 章:簡介Web應用程式Justin Lin
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL Josh Price
 
Ch09 整合資料庫
Ch09 整合資料庫Ch09 整合資料庫
Ch09 整合資料庫Justin Lin
 
Batch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache FlinkBatch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache FlinkVasia Kalavri
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NETAbhi Arya
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean ArchitectureMattia Battiston
 
Stream Processing with Flink and Stream Sharing
Stream Processing with Flink and Stream SharingStream Processing with Flink and Stream Sharing
Stream Processing with Flink and Stream Sharingconfluent
 
Alphorm.com Formation Big Data & Hadoop : Le Guide Complet
Alphorm.com Formation Big Data & Hadoop : Le Guide CompletAlphorm.com Formation Big Data & Hadoop : Le Guide Complet
Alphorm.com Formation Big Data & Hadoop : Le Guide CompletAlphorm
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Edureka!
 
Ch12 Spring 起步走
Ch12 Spring 起步走Ch12 Spring 起步走
Ch12 Spring 起步走Justin Lin
 
Ch03 請求與回應
Ch03 請求與回應Ch03 請求與回應
Ch03 請求與回應Justin Lin
 

What's hot (20)

Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Struts2
Struts2Struts2
Struts2
 
Next.js Introduction
Next.js IntroductionNext.js Introduction
Next.js Introduction
 
Nifi workshop
Nifi workshopNifi workshop
Nifi workshop
 
Servlet & JSP 教學手冊第二版 - 第 1 章:簡介Web應用程式
Servlet & JSP 教學手冊第二版 - 第 1 章:簡介Web應用程式Servlet & JSP 教學手冊第二版 - 第 1 章:簡介Web應用程式
Servlet & JSP 教學手冊第二版 - 第 1 章:簡介Web應用程式
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL
 
Ch09 整合資料庫
Ch09 整合資料庫Ch09 整合資料庫
Ch09 整合資料庫
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Batch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache FlinkBatch and Stream Graph Processing with Apache Flink
Batch and Stream Graph Processing with Apache Flink
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Serialization in .NET
Serialization in .NETSerialization in .NET
Serialization in .NET
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
 
Stream Processing with Flink and Stream Sharing
Stream Processing with Flink and Stream SharingStream Processing with Flink and Stream Sharing
Stream Processing with Flink and Stream Sharing
 
Alphorm.com Formation Big Data & Hadoop : Le Guide Complet
Alphorm.com Formation Big Data & Hadoop : Le Guide CompletAlphorm.com Formation Big Data & Hadoop : Le Guide Complet
Alphorm.com Formation Big Data & Hadoop : Le Guide Complet
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
 
Git Presentation
Git PresentationGit Presentation
Git Presentation
 
Ch12 Spring 起步走
Ch12 Spring 起步走Ch12 Spring 起步走
Ch12 Spring 起步走
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Ch03 請求與回應
Ch03 請求與回應Ch03 請求與回應
Ch03 請求與回應
 

Similar to Struts Interceptors

Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questionsjbashask
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overviewskill-guru
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2Long Nguyen
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questionssurendray
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksSunil Patil
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworksSunil Patil
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2divzi1913
 
Struts(mrsurwar) ppt
Struts(mrsurwar) pptStruts(mrsurwar) ppt
Struts(mrsurwar) pptmrsurwar
 
01 Struts Intro
01 Struts Intro01 Struts Intro
01 Struts Introsdileepec
 
SERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGSERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGPrabu U
 
vRO Training Document
vRO Training DocumentvRO Training Document
vRO Training DocumentMayank Goyal
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction Hitesh-Java
 

Similar to Struts Interceptors (20)

Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questions
 
Struts2
Struts2Struts2
Struts2
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
 
Struts course material
Struts course materialStruts course material
Struts course material
 
important struts interview questions
important struts interview questionsimportant struts interview questions
important struts interview questions
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Skillwise Struts.x
Skillwise Struts.xSkillwise Struts.x
Skillwise Struts.x
 
Struts(mrsurwar) ppt
Struts(mrsurwar) pptStruts(mrsurwar) ppt
Struts(mrsurwar) ppt
 
01 Struts Intro
01 Struts Intro01 Struts Intro
01 Struts Intro
 
Struts Into
Struts IntoStruts Into
Struts Into
 
SERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGSERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMING
 
MVC
MVCMVC
MVC
 
vRO Training Document
vRO Training DocumentvRO Training Document
vRO Training Document
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
 
Asp.net,mvc
Asp.net,mvcAsp.net,mvc
Asp.net,mvc
 

Recently uploaded

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 

Recently uploaded (20)

Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 

Struts Interceptors

  • 1. STRUTS INTERCEPTORS © Onkar Deshpande
  • 2. Agenda  What is Apache Struts 2.x ?  Features of Apache Struts 2.x  How Struts 2.x works ?  Struts 2.x Architecture Overview  Struts 2.0 MVC Components  Request – Response Pipeline  Interceptors  Need of Interceptors  Understanding the Difference Between Filters & Interceptors  Configuring Interceptor  Frameworks(In-built) Interceptors  Custom Inceptors  Disadvantages of Struts 2 © Onkar Deshpande
  • 3. What is Apache Struts 2.x?  Apache Struts 2 is an Open Source, elegant & extensible framework for creating enterprise-ready Java web applications  The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time  It is Action Based Framework  Cerate's web application using MVC 2 architecture  Apache Struts offer two major version  Struts 1.x  Struts 2.x  Struts 2 = WebWork + Struts 3 © Onkar Deshpande
  • 4. Features of Struts 2.x  MVC Framework  Struts provides a unified framework for deploying servlet and JSP applications that use the MVC architecture  A Set of JSP Custom Tag Libraries  Struts provides custom tag libraries for outputting bean properties, generating HTML forms, iterating over various types of data structures, and conditionally outputting HTML  A Collection of Utilities  Struts provides utility classes to handle many of the most common tasks in Web application development 4 © Onkar Deshpande
  • 5. Features of Struts 2.x continued…  Centralized file-based configuration  Rather then hard-coding information into Java programs, many Struts values are represented in XML or property files. This loose coupling means that many changes can be made without modifying or recompiling Java code, and that wholesale changes can be made by editing a single file. This approach also lets Java and Web developers focus on their specific tasks (implementing business logic, presenting certain values to clients, etc.) without needing to know about the overall system layout 5 © Onkar Deshpande
  • 6. Features of Struts 2.x continued…  HTML tags Apache Struts provides a set of custom JSP tags to create HTML forms that are associated with JavaBeans components. This bean/form association serves two useful purposes: It lets you get initial form-field values from Java objects It lets you redisplay forms with some or all previously entered values intact 6 © Onkar Deshpande
  • 7. Features of Struts 2.x continued…  Form field validation  Apache Struts has builtin capabilities for checking that form values are in the required format. If values are missing or in an improper format, the form can be automatically redisplayed with error messages and with the previously entered values maintained  This validation can be performed on the server (in Java), or both on the server and on the client (in JavaScript)  Consistent approach  Struts encourages consistent use of MVC throughout your app 7 © Onkar Deshpande
  • 8. 8 How Struts 2.x works? © Onkar Deshpande
  • 9. Struts 2.x Architecture Overview 9 © Onkar Deshpande
  • 10. Struts 2.x Architecture Overview 10 © Onkar Deshpande
  • 11. Struts 2.0 MVC Components Core components of the framework  Controller:-  Filter Dispatcher:-  First component that start processing that is why this type of MVC is called front controller MVC  Looks at the request and apply the appropriate action.  Struts framework handles all of the controller work.  Its configured in web.xml  Interceptors:-  Can execute code before and after an Action is executed.  They can be configured per action basis.  Can be used for data validation, file upload, double submit guards. 11 © Onkar Deshpande
  • 12. Struts 2.0 MVC Components contd.  Model:-  Implemented by action class  For model you can use any data access technologies like JDBC,EJB,Hibernate  View  Its your result part. It can be JSP,JSTL,JSF etc.  Presentation part of the MVC 12 © Onkar Deshpande
  • 13. Request – Response Pipeline 13 © Onkar Deshpande
  • 14. Need of Interceptors  Many Actions share common concerns  Some Actions need input validated  The framework makes it easy to share solutions to these concerns using an "Interceptor" strategy  Interceptors can execute code before and after an Action is invoked  Interceptors "set the stage" for the Action classes 14 © Onkar Deshpande
  • 15. 15 Interceptor Looks like Filters © Onkar Deshpande
  • 16. Understanding the Difference Filters Interceptors Based on Servlet Specification Based on Struts2. Executes on the pattern matches on the request. Executes for all the request qualifies for a front controller( A Servlet filter ).And can be configured to execute additional interceptor for a particular action execution. Not configurable method calls Methods in the Interceptors can be configured whether to execute or not by means of excludemethods or includeMethods A Servlet Filter is used in the web layer only, you can’t use it outside of a web context. Interceptors can be used anywhere. That’s the main difference. for authentication of web pages you would use a servlet filter For security stuff in your business layer or logging/bugtracing (a.k.a. 16 © Onkar Deshpande
  • 17. Understanding Interceptors 17 © Onkar Deshpande
  • 19. Configuring Interceptor  <action name="login" class=“pack.className"> <interceptor-ref name="timer"/> <interceptor-ref name="logger"/> <result name="input">login.jsp</result> <result name="success“ type="redirectAction">home</result> </action> 19 © Onkar Deshpande
  • 20. Frameworks(In-built) Interceptors  ParametersInterceptor  It sets request parameter into the action  This interceptor gets all parameters from request and sets them on the value stack, typically resulting in the values submitted in a form request being applied to an action in the value stack  AliasInterceptor  Converts similar parameters that may be named differently between requests 20 © Onkar Deshpande
  • 21. Frameworks(In-built) Interceptors cont..  ServletConfigInterceptor  An interceptor which sets action properties based on the interfaces an action implements  For example, if the action implements ServletRequestAware interface then setting of HttpServletRequest is done by this interceptor  This interceptor is designed to set all properties an action needs if it's aware of servlet parameters, the servlet context, the session, etc 21 © Onkar Deshpande
  • 22. Frameworks(In-built) Interceptors cont..  WorkflowInterceptor  An interceptor that makes sure there are not validation errors before allowing the interceptor chain to continue  This interceptor does not perform any validation  ValidationInterceptor  This interceptor runs the action through the standard validation framework  It checks the action against any validation rules (found in files such as ActionClass-validation.xml)  The workflow of the action request does not change due to this interceptor  Rather, this interceptor is often used in conjuction with the workflow interceptor 22 © Onkar Deshpande
  • 23. Disadvantages of Struts  Bigger learning curve  To use MVC with the standard RequestDispatcher, you need to be comfortable with the standard JSP and servlet APIs. To use MVC with Struts, you have to be comfortable with the standard JSP and servlet APIs and a large and elaborate framework that is almost equal in size to the core system. This drawback is especially significant with smaller projects, near-term deadlines, and less experienced developers; you could spend as much time learning Struts as building your actual system  Poor documentation  Compared to the standard servlet and JSP APIs, Struts has fewer online resources, and many first-time users find the online Apache documentation confusing and poorly organized. There are also fewer books on Apache Struts than on standard servlets and JSP 23 © Onkar Deshpande
  • 24. Disadvantages of Struts  Less transparent  With Struts applications, there is a lot more going on behind the scenes than with normal Java-based Web applications. As a result, Struts applications are:  Harder to understand  Harder to benchmark and optimize  Rigid approach  The flip side of the benefit that Struts encourages a consistent approach to MVC is that Struts makes it difficult (but by no means impossible) to use other approaches 24 © Onkar Deshpande
  • 25. 25 Thank You © Onkar Deshpande