/* * servlet1.java 4/14/99 Jocelyn Becker * */ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * * This is a simple example of an HTTP Servlet that responds to input * parameters such as form input. */ public class servlet1 extends HttpServlet { /** * Handle the GET and HEAD methods by building a simple web page. * The doGet method parses the input parameters and constructs * an output page based on the information received from the form. */ public void doGet ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { PrintWriter out; String title = "Example Form Response"; // Set content type and other response header fields first. response.setContentType("text/html"); // Get an output stream. out = new java.io.PrintWriter(response.getOutputStream ()); // Print the HTML, HEAD, and TITLE tags. out.println("
This page was generated by a servlet.
"); // Print the query string just for informational purposes. String queryString = request.getQueryString(); out.println("The query string is " + queryString + "
");
// Extract the values of the parameters sent by the form.
// If a parameter does not exist, getParameter() returns null.
String companyname = request.getParameter("companyname");
String numberofpeople = request.getParameter("numberofpeople");
String companysize = "";
String hosting = request.getParameter("hosting");
String design = request.getParameter("design");
String javadev = request.getParameter("javadev");
// Display the input parameters
out.println("
The values of the parameters sent by the form are:
"); out.println("number of people: " + numberofpeople); out.println(""); // For the main part of the page, construct // a customized message encouraging the user // to use our company to help with its web needs. // Construct an unordered list of the skills needed. // First test if any skills are needed. // If the user did not select any skills, create a generic message. // Otherwise create an unordered list with a bullet item for each skill selected. String skillsneeded = ""; if (( hosting == null) && (design == null) && (javadev == null)) { skillsneeded = " all your web server requirements."; } else { skillsneeded = "
company name: " + companyname); out.println("
hosting: " + hosting); out.println("
design: " + design); out.println("
javadev: " + javadev + "