title: make servlet filter applicable for all web applications
body: <p>I am developing a web application using JSP &amp; Servlets.</p>
  
  <p>I have developed a <code>servlet filter</code> for <code>Login</code> purpose. Which checks whether user is logged in or not, if user is logged in then it allows access to the requested resource, else it redirects request to the <code>Login page</code>. And it works perfectly.</p>
  
  <p><strong>Filter</strong></p>
  
  <pre><code>public class MyFilter implements Filter
  {
      public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException 
      {
          //code here
      }
  }
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;MyFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;com.myfilter.MyFilter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;PARAM_NAME_HERE&lt;/param-name&gt;
          &lt;param-value&gt;PARAM_VALUES_HERE&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;MyFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>Now I have deployed this application named <code>Login</code> on <code>Tomcat 7</code>. This <code>servlet filter</code> works perfectly for the resources (JSPs, Servltes, .css, .js) in this web application.</p>
  
  <p>So now in <code>Tomcat</code> there are other web applications like <code>Profiles</code>, <code>Distribution</code> etc. So now what I want is apply the <code>Filter</code> in <code>Login</code> application <em>Applicable</em> for all other applications deployed in the <code>Tomcat</code>. Means every request to other application resources should go through the <code>Filter</code> which I have developed.</p>
  
  <p>So any suggestions will be appreciated!</p>
  
  <p><strong>Edit1</strong></p>
  
  <p>I dont want to put package which contains <code>Filter</code> in other applications.  Because in Tomcat server there are more than 10 applications are deployed, and some more are going to be deployed. So suppose if I put the package which contains <code>Filter</code> in all other applications and do servlet mapping , but if some days after I want to make some changes in the Filter then I will need to make changes in all applications, and redeploying them will be needed.</p>