title: Redirect using Spring boot interceptor
body: <p>I have created a web app using spring boot and freemarker and implemented interceptor(HandlerInterceptorAdapter).</p>
  
  <p>Inside the interceptor, when user is not logged then it will redirect to login page. This works fine. But the problem is that the controller is being executed first before redirecting to the login page.</p>
  
  <p>My Interceptor Code:</p>
  
  <pre><code>public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object) throws Exception {
          User userSession = (User) request.getSession().getAttribute("user");
          if (userSession == null) {
              response.sendRedirect("/login");
          }
      }
  </code></pre>
  
  <p>Controller class(after response.sendRedirect, this controller is still being excuted). Why? I'm stack in with this problem.</p>
  
  <pre><code>@RequestMapping("/home")
      public String home(Model model, HttpServletRequest httpServletRequest) {
  
          String returnPage = "home-admin";
  
          User user = (User) httpServletRequest.getSession().getAttribute("user");
          if(user != null){
              String accessType = accessTypeRepository.getAccessType(user.getAccessId());
              if(StrUtil.isEqual(accessType, AccessTypeConst.MANAGER.getType())){
                  returnPage = "home-manager";
              }
          }
          return returnPage;
      }
  </code></pre>