He considered having just a single servlet, with a bunch of if tests, but decided that separate servlets would be more OO—each servlet should have one responsibility like the query page, the sign-up page, the search results page, etc.
Each servlet will have all the business logic it needs to modify or read the database, and prints the HTML to the response stream back to the client.
// import statements public class DatingServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { // business logic goes here, depending // on what this servlet is supposed to do // (write to the database, do the query, etc.) PrintWriter out = response.getWriter(); // compose the dynamic HTML page out.println( "something really ugly goes here"); } }