import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class SiteSelector extends HttpServlet { Vector sites = new Vector(); Random random = new Random(); public void init(ServletConfig config) throws ServletException { super.init(config); sites.addElement("http://www.oreilly.com/catalog/jservlet"); sites.addElement("http://www.servlets.com"); sites.addElement("http://jserv.java.sun.com"); sites.addElement("http://www.servletcentral.com"); } public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); int siteIndex = Math.abs(random.nextInt()) % sites.size(); String site = (String)sites.elementAt(siteIndex); res.setStatus(res.SC_MOVED_TEMPORARILY); res.setHeader("Location", site); } }