import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class MyServlet extends HttpServlet {
Vector sites = new Vector();
Random random = new Random();
public void init() throws ServletException {
sites.addElement("http://www.java2java.com/Code/Java/CatalogJava.htm");
sites.addElement("http://www.java2java.com/Tutorial/Java/CatalogJava.htm");
sites.addElement("http://www.java2java.com/Article/Java/CatalogJava.htm");
sites.addElement("http://www.java2java.com/Product/Java/CatalogJava.htm");
}
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);
}
}
|