import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; // File: EchoMagazineServlet.java // Listing 4 // /** * This servlet displays the fields of a magazine subscription form in a web page. * * @author Chad (shod) Darby, darby@j-nine.com * @version 5.49, 2 Nov 1997 * */ public class EchoMagazineServlet extends HttpServlet { private int counter; public void init(ServletConfig config) throws ServletException { super.init(config); counter = 0; } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String replyPage = null; // our servlet is being called, increment the counter // counter++; // Build HTML page's header information // replyPage = "
We will send the magazine to the mailing address below."; // Print out the values for form variables. // Notice we use HTML formatting to "spiff-up" the data // replyPage += "
" + this.getServletInfo(); // Build bottom of HTML page // replyPage += ""; // Set the content-type for the response header // response.setContentType("text/html"); // finally, send this formatted HTML page back to the client // PrintWriter out = new PrintWriter(response.getOutputStream()); out.println(replyPage); out.close(); } public String getServletInfo() { return "Echo Magazine Form Servlet v5.49, 2 Nov 1997"; } }