title: Is it necessary to make <listener-class> tag entry in web.xml even after adding @WebListener annotation to my listener class?
body: <p>Is it necessary to make listener-class tag entry in web.xml even after adding @WebListener annotation to my listener class? </p>
  
  <p>Because when I use just @WebListener annotation without making listener-class tag entry in web.xml, my listener class does not get executed.  </p>
  
  <p>When I use both the listener-class tag entry in web.xml and @WebListener for my listener class, then only my listener class is getting executed.</p>
  
  <p>(<em>Additional info: java version "1.7.0_79" , Java(TM) SE Runtime Environment (build 1.7.0_79-b15</em>)</p>
  
  <p>Following is the listener-class tag entry in web.xml :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;listener&gt;
          &lt;listener-class&gt;  org.shan.jspservlets.CountUserListener &lt;/listener-class&gt;
  &lt;/listener&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Following is my listener class :
  <div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>package org.shan.jspservlets;
  
  import javax.servlet.ServletContext;
  import javax.servlet.annotation.WebListener;
  import javax.servlet.http.HttpSessionEvent;
  import javax.servlet.http.HttpSessionListener;
  
  @WebListener
  public class CountUserListener implements HttpSessionListener {
   ServletContext ctx = null;
   static int total = 0, current = 0;
  
   public void sessionCreated(HttpSessionEvent e) {
    total++;
    current++;
  
    ctx = e.getSession().getServletContext();
    ctx.setAttribute("totalusers", total);
    ctx.setAttribute("currentusers", current);
  
   }
  
   public void sessionDestroyed(HttpSessionEvent e) {
    current--;
    ctx.setAttribute("currentusers", current);
   }
  
  }</code></pre>
  </div>
  </div>
  </p>