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:
Create a class named
PromoCodeInterceptor
under thecom.packt.webstore.interceptor
package in the source foldersrc/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; public class PromoCodeInterceptor extendsHandlerInterceptorAdapter { private String promoCode; private String errorRedirect; private String offerRedirect; public boolean preHandle(HttpServletRequest request...