title: Implementing HTTP Basic Authentication in a servlet
body: <p>I want to write a servlet that wraps around a set of resources and needs to protect them with basic HTTP auth; the submitted username/pass will be checked against the backend database before serving the file. </p>
  
  <p>Does anyone have any working examples of this? I tried the sample at <a href="http://www.coderanch.com/t/352345/Servlets/java/HTTP-basic-authentication-Web-Applications" rel="noreferrer">http://www.coderanch.com/t/352345/Servlets/java/HTTP-basic-authentication-Web-Applications</a> but it kept returning an <code>IllegalStateException</code> in the <code>sendError</code> call.</p>