Print the HTML for the next advertisement for a user.
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
// If the list-of-ads file has changed, reload it.
// Synchronized so we only reload once, to avoid having
// multiple threads calling load().
synchronized(this) {
if (load_time < file.lastModified()) {
out.println("<!-- reloaded adrotator -->");
list = AdAccessor.load(file);
load_time = file.lastModified();
}
}
// Pick an ad at random from the list
int n = r.nextInt(list.size());
Ad ad = (Ad)list.get(n);
// Convert it to HTML
out.println("<!-- Ad link made by AdServlet -->");
out.println(ad.html);