SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Express node js
Express node jsExpress node js
Express node js
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Module design pattern i.e. express js
Module design pattern i.e. express jsModule design pattern i.e. express js
Module design pattern i.e. express js
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring boot
Spring bootSpring boot
Spring boot
 
Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Spring security
Spring securitySpring security
Spring security
 
Building an API with Django and Django REST Framework
Building an API with Django and Django REST FrameworkBuilding an API with Django and Django REST Framework
Building an API with Django and Django REST Framework
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & Streams
 
Arquitetura Node com NestJS
Arquitetura Node com NestJSArquitetura Node com NestJS
Arquitetura Node com NestJS
 
Swagger / Quick Start Guide
Swagger / Quick Start GuideSwagger / Quick Start Guide
Swagger / Quick Start Guide
 
Server side rendering review
Server side rendering reviewServer side rendering review
Server side rendering review
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
React workshop
React workshopReact workshop
React workshop
 

Ähnlich wie 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
 

Ähnlich wie 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
 
Struts Into
Struts IntoStruts Into
Struts Into
 
01 Struts Intro
01 Struts Intro01 Struts Intro
01 Struts Intro
 
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
 

Kürzlich hochgeladen

%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benonimasabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 

Kürzlich hochgeladen (20)

%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 

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