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?

Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.David Gómez García
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features OverviewSergii Stets
 
What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaEdureka!
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web APIBrad Genereaux
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
Awskrug AWS SNS, SQS, and SES
Awskrug AWS SNS, SQS, and SESAwskrug AWS SNS, SQS, and SES
Awskrug AWS SNS, SQS, and SESJungHakLee4
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 

Was ist angesagt? (20)

Junit
JunitJunit
Junit
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Java 8 - Features Overview
Java 8 - Features OverviewJava 8 - Features Overview
Java 8 - Features Overview
 
Spring boot
Spring bootSpring boot
Spring boot
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | Edureka
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Struts
StrutsStruts
Struts
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Awskrug AWS SNS, SQS, and SES
Awskrug AWS SNS, SQS, and SESAwskrug AWS SNS, SQS, and SES
Awskrug AWS SNS, SQS, and SES
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
Spring boot
Spring bootSpring boot
Spring boot
 

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

Kürzlich hochgeladen

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 

Kürzlich hochgeladen (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 

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