title: interceptors in spring MVC
body: <p>I am trying learn Interceptors in spring but not able to understand it. I tried a sample example but get no success. I have created a simple interceptor like</p>
  
  <pre><code>@Component("testInterceptor")
  public class testInterceptor extends HandlerInterceptorAdapter {      
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,   Object handler){
  //I suppose this method will be called when I open my login page so just write something here       
          System.out.println("Inside Interceptor...");
          ModelAndView mv = new ModelAndView();
          mv.addObject("name", "test name");
          return true;
  }
  
  }
  </code></pre>
  
  <p>In my spring-servlet.xml I have </p>
  
  <blockquote>
  <pre><code>&lt;context:component-scan base-package="com.test.interceptor" /&gt;
   &lt;mvc:interceptors&gt;
              &lt;bean class="com.test.interceptors.testInterceptor " /&gt;         
  &lt;/mvc:interceptors&gt;
  </code></pre>
  </blockquote>
  
  <p>On my login page I write somewhere ${name}</p>
  
  <p>So I can't even see even ${name} value or sysout anywhere.</p>
  
  <p>I am not even able to understand when postHandler or afterCompletion method will be called and how I can test them before implementing. This may be because I am new to spring also and I am not able to understand it fully. It would be great help if you suggest some good link to  read which shows some examples.</p>
  
  <p>Thanks in advance</p>
  
  <p>Edited:
  Now I can see my sysout commnet when I call my login page but it displaying it 16 times why is this so? </p>