Ask for a password from a Servlet

From CodeCodex

Implementations[edit]

Java[edit]

public void askPassword(HttpServletResponse response) {
  response.setStatus(response.SC_UNAUTHORIZED); 
  response.setHeader("WWW-Authenticate",
     "BASIC realm=\"protected-area\"");
  }

then the browser will popup a dialog for username/password