O'Reilly logo

Spring MVC Beginner’s Guide by Amuthan G

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – intercepting offer page requests

For example, consider a situation where you want to show the special offer products page to only those users who have a valid promo code. The others trying to access the special offer products page with an invalid promo code should be redirected to an error page. Achieve this piece of functionality with the help of the interceptor by performing the following steps:

  1. Create a class named PromoCodeInterceptor under the com.packt.webstore.interceptor package in the source folder src/main/java and add the following code into it:
    package com.packt.webstore.interceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required