title: Should I avoid use of filters in servlets to check whether user is logged in
body: <p>I'm developing my first Java based website. To check whether user is logged in when accessing profile or any other sensitive resources, I implement filters.
  Because I found everywhere on the internet that we should use filters for login check (>as it seems like it's the "standard" way of coding).
  But it only performs the following checks :</p>
  
  <pre><code>if(session.getAttribute("user")==null||session.getAttribute("user")=="")
       request.getRequestDispatcher("WEB-INF\\webpages\\SignIn.html").include(request, response);
  else
      chain.doFilter().
  </code></pre>
  
  <p>But to avoid "NullPointerException" I am already implementing the following "check" everywhere:</p>
  
  <pre><code>if(session.getAttribute("user")==null||session.getAttribute("user")=="")
  </code></pre>
  
  <p>So I don't feel that I should use filters for login check because anyhow it is increasing complexity of the code design such as putting extra efforts in url mappings etc.
  So, Should I really use Filters "only for login checks"?</p>