A Java Servlet can generate a page in several ways, including:
- Using the PrintWriter class to write plain text or HTML to the response.
- Using the JSP (JavaServer Pages) technology to create dynamic web pages.
- Using the ServletOutputStream class to write binary data to the response.
- Using a template engine like Freemarker or Velocity to generate the page from a template.
- Forwarding the request to another servlet or JSP page using the RequestDispatcher.
- Redirecting the client to another page using the sendRedirect method.
So far your servlets have only generated HTML, which is an important aspect of servlets. However most of them will consist of additional functionality. In the next module database access using servlets will be discussed.