package Acme.Serve.mrh;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

import Acme.Serve.servlet.*;
import Acme.Serve.servlet.http.*;
import java.io.*;

public class ColorTester extends HttpServlet {
  public void service(HttpServletRequest request,
                      HttpServletResponse response)
      throws ServletException, IOException {
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("text/html");
    ServletOutputStream out = response.getOutputStream();
    String bgColor = request.getParameter("Background");
    if (bgColor == null || bgColor.equals(""))
      bgColor = "white";
    String fgColor = request.getParameter("Foreground");
    if (fgColor == null || fgColor.equals(""))
      fgColor = "black";
    out.println
      ("<!DOCTYPE HTML PUBLIC " +
         "\"-//W3C//DTD HTML 3.2//EN\">\n" +
       "<HTML>\n" +
       "<HEAD>\n" +
       "<TITLE>ColorTester</TITLE>\n" +
       "</HEAD>\n" +
       "\n" +
       "<BODY BGCOLOR=\"" + bgColor + "\"\n" +
       "      TEXT=\"" + fgColor + "\">\n" +
       "<H1>ColorTester</H1>\n" +
       "Based on your input, this page is being\n" +
       "displayed with a background color of\n" +
       "'" + bgColor + "' and a foreground color of\n" +
       "'" + fgColor + "'.\n" +
       "</BODY>\n" +
       "</HTML>");
  }
}
