Listing 1. Simple Servlet

public class HelloWorldServlet extends HttpServlet
   {
   public void doGet (HttpServletRequest request,
   HttpServletResponse response)
   throws ServletException, IOException
   {
      PrintWriter out;
      // set the content type
      response.setContentType("text/html");
      out = response.getWriter();
      out.println("<HTML><HEAD><TITLE>");
      out.println("Hello World Servlet");
      out.println("</TITLE></HEAD><BODY>");
      out.println("<H1>Hello World</H1>");
      out.println("</BODY></HTML>");
      out.close();
   }
   }