FileDocCategorySizeDatePackage
AreaCode.javaAPI DocExample5388Thu Apr 05 01:37:56 BST 2001None

AreaCode

public class AreaCode extends HttpServlet

Fields Summary
Properties
lookup
private Object[]
data
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    res.setContentType("text/vnd.wap.wml");
    PrintWriter out = res.getWriter();

    String msg = null;

    String code = req.getParameter("code");
    String region = null;
    if (code != null) {
      region = lookup.getProperty(code);
    }

    out.println("<?xml version=\"1.0\"?>");
    out.println("<!DOCTYPE wml PUBLIC " +
                "\"-//WAPFORUM//DTD WML 1.1//EN\" " +
                "\"http://www.wapforum.org/DTD/wml_1.1.xml\">");

    out.println("<wml>");
    out.println("<card id=\"Code\" title=\"Code\">");
    out.println("  <p>");
    out.println("  Area code '" + code + "'<br/>");
    if (region != null) {
      out.println("  is " + region + ".<br/>");
    }
    else {
      out.println("  is not valid.<br/>");
    }
    out.println("  </p>");
    out.println("</card>");
    out.println("</wml>");
  
public voidinit()


     
    // Transfer raw data from below into a fast-lookup Properties list
    for (int i = 0; i < data.length; i++) {
      Object[] record = data[i];
      String state = (String) record[0];
      int[] codes = (int[]) record[1];
      for (int j = 0; j < codes.length; j++) {
        lookup.put(String.valueOf(codes[j]), state);
      }
    }