title: javax.servlet.ServletException at javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
body: <p>I am working with JSF 2.0, tomcat 7.0, mojarra 2.0.3 and primefaces. 
  The problem is that I implemented unsuccessfully javax.servlet.Filter class to redirect to the login page if a user tries to enter a page without having logged in, but I am also using FileUpload to upload files to server, which I think is what is me and trigger conflict with the doFilter method, the server throws me the following exception: </p>
  
  <pre><code>javax.servlet.ServletException 
  javax.faces.webapp.FacesServlet.service (FacesServlet.java: 321) 
  org.primefaces.webapp.filter.FileUploadFilter.doFilter (FileUploadFilter.java: 98) 
  org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java: 52)
  </code></pre>
  
  <p>I configured the web.xml file as follows:</p>
  
  <pre><code>&lt;!--this may be the cause of the error--!&gt;
  
    &lt;filter&gt;
  &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
  &lt;filter-class&gt;org.primefaces.webapp.filter.FileUploadFilter&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
  &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
  &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;/filter-mapping&gt;
    &lt;filter&gt;
  &lt;filter-name&gt;Login&lt;/filter-name&gt;
  &lt;filter-class&gt;controller.BeanFiltersession&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
  &lt;filter-name&gt;Login&lt;/filter-name&gt;
  &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>after that delete the class that implemented Filter and erased the lines in the web.xml file, but the error still persists 
  any idea how to fix it?</p>
  
  <p>the problem is not the FileUpload problem is between primefaces, I think the problem is that as I indicated one filter to validate sessions using HttpSession and HttpServletRequest, upon login sends me this exception, it is clear that delete the class that implemented Filter, probe the FileUpload and works without problems, but I think the changes I made in that class were recorded at api.jar servlet-api having Tomcat 7.0 my code is as follows: </p>
  
  <pre><code>package validators;
  import javax.faces.context.FacesContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  public class SessionValidator {
  public static HttpSession getSesion(){
      return (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
  }
  public static HttpServletRequest getRequest(){
      return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
  }
  public static String getUser(){
      HttpSession sesion= (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
      return sesion.getAttribute("usuario").toString();
  }   
  public static String getNivel(){
      HttpSession sesion=getSesion();
      if(sesion !=null){
          return sesion.getAttribute("nivel").toString();
      }else{
          return null;
      }
  }
  }
  </code></pre>
  
  <p>The SessionValidator class called when I login in my code is this:</p>
  
  <pre><code>package controller;
  import java.io.Serializable;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import javax.faces.application.FacesMessage;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  import javax.faces.context.FacesContext;
  import javax.faces.event.ActionEvent;
  import javax.servlet.http.HttpSession;
  
  import org.primefaces.context.RequestContext;
  
  import validators.SessionValidator;
  import model.csConexion;
  import model.csSesion;
  
  @ManagedBean
  @SessionScoped
  public class BeanSesion implements Serializable{
  
  
  private static final long serialVersionUID = 1L;
  
  private csSesion sesion;
  private csConexion con;
  HttpSession session;
  private String usuario;
  private String nivel;
  
  public BeanSesion(){
      sesion=new csSesion();
      con=new csConexion();
  }
  public String getUsuario(){
  
  return SessionValidator.getUser();
  }
  public void setUsuario(String usuario){
  
      this.usuario=usuario;
  }
  public String getNivel(){
      if(SessionValidator.getSesion().getAttribute("usuario")!=null){
          return SessionValidator.getNivel();
      }else{
          return "";
      }
  }
  public void setNivel(String nivel){
  
      this.nivel=nivel;
  }
  
  public csSesion getSesion(){
      return sesion;
  }
  public void setSesion(csSesion sesion){
      this.sesion=sesion;
  }
  public String iniciarsesion(ActionEvent e){
      RequestContext context= RequestContext.getCurrentInstance();
      FacesContext fcontext= FacesContext.getCurrentInstance();
      FacesMessage message=null;
      boolean ok=false;
      ResultSet rs;
  
      try {
          if(con.conectar()==true){
              String sql="select*from usuario where usuario=? and contrasenia=?";
              PreparedStatement comando= con.getConexion().prepareStatement(sql);
              comando.setString(1,sesion.getUsuario());
              comando.setString(2,sesion.getContrasenia());
              rs=comando.executeQuery();
              if(rs.next()){
                  nivel= rs.getString("nivel");
                  usuario= rs.getString("usuario");
                  ok=true;
                  session= SessionValidator.getSesion();
                  session.setAttribute("usuario", usuario);
                  session.setAttribute("nivel", nivel);
  
  
                  message= new FacesMessage(FacesMessage.SEVERITY_INFO,"¡Bienvenido!",sesion.getUsuario());
  
                  try {
                      if(nivel.equals("master")){
                      fcontext.getExternalContext().redirect("admin/admin.xhtml");
                      }else if(nivel.equals(null)){
                          fcontext.getExternalContext().redirect("index.xhtml");
                      }
  
                  } catch (Exception e2) {
                      e2.printStackTrace();
                      message= new FacesMessage(FacesMessage.SEVERITY_WARN,"Error","Error");
                  }
              }else{
                  ok=false;
                  message= new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Usuario o contraseña inválidos");
              }
              FacesContext.getCurrentInstance().addMessage(null,message);
              context.addCallbackParam("Ok", ok);
          }
      } catch (Exception ex) {
          ex.printStackTrace();
          ok=false;
      }
      finally{
          System.out.println(nivel);
          con.desconectar();
      }
      return nivel;
  }
  }
  </code></pre>
  
  <p>and this is the exception send Tomcat:</p>
  
  <pre><code>excepción 
  javax.servlet.ServletException: null source
  javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
  org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  causa raíz 
  java.lang.IllegalArgumentException: null source
  java.util.EventObject.&lt;init&gt;(Unknown Source)
  javax.faces.event.SystemEvent.&lt;init&gt;(SystemEvent.java:67)
  javax.faces.event.ComponentSystemEvent.&lt;init&gt;(ComponentSystemEvent.java:69)
  javax.faces.event.PostRestoreStateEvent.&lt;init&gt;(PostRestoreStateEvent.java:69)
  com.sun.faces.lifecycle.RestoreViewPhase.deliverPostRestoreStateEvent(RestoreViewPhase.java:256)
  com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:245)
  com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
  com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:107)
  com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
  javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
  org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>