Listing 2. PrintFooServlet.java, a Servlet Version of PrintFoo.java

// Servlet version of PrintFooServlet
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Bring in the DOM classes which come with Enhydra
import org.w3c.dom.html.*;
// Bring in the "foo" class
import il.co.lerner.*;
public class PrintFooServlet extends HttpServlet {
   public void doGet(HttpServletRequest request,
       HttpServletResponse response)
       throws IOException, ServletException
   {
      // Set the MIME content type for the response
      response.setContentType("text/html");
      // Get the output stream to STDOUT
      PrintWriter out = response.getWriter();
      // Create an instance of our "foo" page object.
      foo myfoo = new foo();
      // Change the text in our "firstpara" paragraph.
      myfoo.setTextFirstpara("This has been changed");
      // Display the results
      out.println(myfoo.toDocument());
   }
}