title: Servlet filters not working properly
body: <p>I have a login.java servlet, from where after taking the username and password, if correct, we are directed to welcome.java servlet.A filter named loginfilter.java verifies the username and password. If the username and password are not correct, i have an errorpage.java servlet which is then called.</p>
  
  <p>My filter is not working which i dont know why. i think my web.xml code and filters code are correct. Plz help me find out the error. </p>
  
  <p>Here is the code for my filter</p>
  
  <pre><code>package filters;
  
  
  import java.io.IOException;
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  
  public class loginfilter implements Filter{
  
      @Override
      public void init(FilterConfig filterConfig) throws ServletException {
          throw new UnsupportedOperationException("Not supported yet.");
      }
  
      @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain
      chain throws IOException, ServletException     {
             String u=request.getParameter("username");
             String p=request.getParameter("password");
             String user="akshay";
             String pass="akshay";
             if (u.equals(user) &amp;&amp; p.equals(pass)){
                 chain.doFilter(request,response);
             }        
       }
  
      @Override
      public void destroy() {
          throw new UnsupportedOperationException("Not supported yet.");
      }
  
      private RequestDispatcher getReuestDispatcher(String loginpage) {
          throw new UnsupportedOperationException("Not supported yet.");
      }
  
  }
  </code></pre>
  
  <p>Here is the code for web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;login&lt;/servlet-name&gt;
          &lt;servlet-class&gt;login&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;welcomepage&lt;/servlet-name&gt;
          &lt;servlet-class&gt;welcomepage&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;errorpage&lt;/servlet-name&gt;
          &lt;servlet-class&gt;errorpage&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;login&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/login&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;error-page&gt;
          &lt;error-code&gt;404&lt;/error-code&gt;
          &lt;location&gt;/errorpage&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;error-code&gt;403&lt;/error-code&gt;
          &lt;location&gt;/errorpage&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;exception-type&gt;javax.servlet.ServletException&lt;/exception-type&gt;
          &lt;location&gt;/errorpage&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;exception-type&gt;javax.io.IOException&lt;/exception-type&gt;
          &lt;location&gt;/errorpage&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;loginfilter&lt;/filter-name&gt;
          &lt;filter-class&gt;filters.loginfilter&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;loginfilter&lt;/filter-name&gt;
          &lt;servlet-name&gt;welcomepage&lt;/servlet-name&gt;
      &lt;/filter-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;welcomepage&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/welcomepage&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;errorpage&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/errorpage&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
  &lt;/web-app&gt;
  </code></pre>