Book Image

Spring MVC Beginner's Guide

By : Amuthan Ganeshan
Book Image

Spring MVC Beginner's Guide

By: Amuthan Ganeshan

Overview of this book

Table of Contents (19 chapters)
Spring MVC Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 6. Intercept Your Store with Interceptor

In all the previous chapters, we have only learned how to map a request to a controller method. Once the request reaches the controller method, we execute some logic and return a logical view name that can be used by the view resolver to resolve views. However, what if we want to execute some logic before the actual request process is performed? Similarly, what if we want to execute another instruction before dispatching the response?

The Spring MVC interceptor can be used to intercept the actual request and response. Interceptors are a special web programming technique where one can execute a certain piece of logic before or after a web request is processed. In this chapter, we are going to learn more about the interceptor. We will learn the following:

  • How to configure an interceptor

  • How to add internalization support

  • Data auditing using an interceptor

  • Conditional redirecting using an interceptor