HttpServletRequest req = null;
boolean authenticated = false;
PrintWriter out = null;
if (request instanceof HttpServletRequest){
req = (HttpServletRequest) request;
String user = req.getParameter("user");
authenticated = authenticateUser(user);
}
if (authenticated){
chain.doFilter(request,response);
} else {
response.setContentType("text/html");
out = response.getWriter();
out.println("<html><head><title>Authentication Response</title></head><body>");
out.println("<h2>Sorry your authentication attempt failed</h2>");
out.println("</body></html>");
out.close();
}