import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

import HTML.*;

public class SearchServlet extends HttpServlet {

  //Initialize global variables
  private Integer initparam = null;

  public void init(ServletConfig config)
    throws ServletException {

    super.init(config);
  }

  public HTMLForm buildCatalogSearchForm() {

    // Instantiate the HTMLForm object
    HTMLForm search_form = new HTMLForm();
    
    // This is a dummy action, it is only meant as an example
    // We will connect the SearchTool to the database in
    // Chapter 8
    search_form.setAction("http://localhost:8080/servlet" +
      "/ToBeConnectedLater");

    // Set the Post method to true
    search_form.setPostMethod(true);

    try {

      // Center the Form
      search_form.setAlignment(HTMLObject.CENTER);

      // Add a HTMLTextInput
      HTMLTextInput text_input = new HTMLTextInput();
      text_input.setName("search_string");
      text_input.setSize(30);
      search_form.addObject(text_input);

      // Add a HTMLButton to Invoke the Action
      HTMLSubmitButton button = new HTMLSubmitButton();
      button.setValue("Search");
      search_form.addObject(button);
    }
    catch ( Exception e ) {

      System.err.println(e.getMessage());
    }
    return search_form;
  }

  //Process the HTTP Get request
  public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {

    response.setContentType("text/shtml");
    PrintWriter out = response.getWriter();

    out.println(buildCatalogSearchForm().toHTML());
    out.close();
  }

  //Get Servlet information
  public String getServletInfo() {
    return "SearchServlet Information";
  }
}
