title: The servlet call order failed
body: <p>Good afternoon!
  In an example I did in class, when I debug the servlet comes in front of the filter.</p>
  
  <p>On the system I'm doing the filter is called first that the servlet ... and this is causing problems.</p>
  
  <p>I'm doing the login part of the system.</p>
  
  <p>I am using version 3.0 of the servlet.</p>
  
  <p>In class I did not need to use xml, but in some sites indicate to do this ... which also did not work.</p>
  
  <p><strong>Index</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
              &lt;div&gt;
              &lt;form action="template/inicio.html" method="post"&gt; 
                  &lt;label for="login"&gt;Login &lt;/label&gt;     
                  &lt;input type="text" name="login"&gt;
  
                  &lt;br&gt;
  
                  &lt;label for="senha"&gt;Senha &lt;/label&gt; 
                  &lt;input type="text" name="senha"&gt;
  
                  &lt;br&gt;
  
                  &lt;input type="submit" value="Entrar"&gt;
              &lt;/form&gt;   
          &lt;/div&gt;
          ${msg}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>FiltroLogin</strong></p>
  
  <pre><code>package filtro;
  
  import java.io.IOException;
  
  import javax.servlet.DispatcherType;
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.annotation.WebFilter;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  /**
  * Servlet Filter implementation class FiltroLogin
  */
  @WebFilter(
          dispatcherTypes = {
                  DispatcherType.REQUEST, 
                  DispatcherType.FORWARD, 
                  DispatcherType.INCLUDE, 
                  DispatcherType.ERROR
          }
                      , 
          urlPatterns = { 
                  "/FiltroLogin", 
                  "/template/*"
          })
  public class FiltroLogin implements Filter {
  
      /**
      * Default constructor. 
      */
      public FiltroLogin() {
          // TODO Auto-generated constructor stub
      }
  
      /**
      * @see Filter#destroy()
      */
      public void destroy() {
          // TODO Auto-generated method stub
      }
  
      /**
      * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
      */
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
  
          HttpServletResponse res = (HttpServletResponse) response;
          HttpServletRequest req = (HttpServletRequest) request;
          HttpSession session = req.getSession();
  
  
  
          if(session.getAttribute("login") != null ){
              //Se estiver logado, deixa a pagina ser exibida
              chain.doFilter(request, response);
          }else{
              //mandar embora
              res.sendRedirect( req.getContextPath() );
          }
      }
  
      /**
      * @see Filter#init(FilterConfig)
      */
      public void init(FilterConfig fConfig) throws ServletException {
          // TODO Auto-generated method stub
      }
  
  }
  </code></pre>
  
  <p><strong>ControleLogin</strong></p>
  
  <pre><code>package control;
  
  import java.io.IOException;
  import java.util.List;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  import org.firebirdsql.jdbc.parser.JaybirdSqlParser.function_return;
  
  import model.Funcionario;
  import persistence.FuncionarioDao;
  import persistence.LoginDao;
  
  /**
  * Servlet implementation class ControleLogin
  */
  @WebServlet({"/ControleLogin","/template/inicio.html", "/template/logout.html"})
  public class ControleLogin extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
      * @see HttpServlet#HttpServlet()
      */
      public ControleLogin() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          execute(request, response);
      }
  
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          execute(request, response);
      }
  
  protected void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          try{
  
                  String url = request.getServletPath();
  
                  if(url.equalsIgnoreCase("/template/inicio.html")){
                      String login = request.getParameter("login");
                      String senha = request.getParameter("senha");
  
                  if(new LoginDao().logar(login, senha).booleanValue() == true){
                      Funcionario func = new LoginDao().buscarUsuario(login);
  
                      HttpSession session = request.getSession();
  
                      session.setAttribute("nomeP", func.getNome());
  
                      response.sendRedirect("template/indCadastro.jsp");
                  }else{
                      request.setAttribute("msg", "&lt;div class = 'alert alert-info'&gt;"+ "Email ou senha Incorretos!"+"&lt;/div&gt;");
                      request.getRequestDispatcher("../index.jsp").forward(request, response);
                  }
  
                  }else if(url.equalsIgnoreCase("/template/logout.html")){
                      HttpSession session = request.getSession();
  
                      session.removeAttribute("nomeP");
  
                      session.invalidate();
  
                      response.sendRedirect( request.getContextPath() + "/");
                  }
  
          }catch(Exception e){
              e.printStackTrace();
          }
      }
  }
  </code></pre>