Listing A
public class SimpleServlet extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SomeBusinessComponent someBusinessComponent = new SomeBusinessComponent(); String responseData = someBusinessComponent.execute(request); // content type and other headers must be set first response.setContentType("text/html"); // data for the response is written to the HTTP stream // using a standard java.io.PrintWriter object PrintWriter out = response.getWriter(); out.println("<HTML><HEAD><TITLE>"); out.println(title); out.println("</TITLE></HEAD><BODY>"); out.println("<H1>Simple Servlet Response</H1>"); out.println(responseData); out.println("</BODY></HTML>"); out.close(); } }