Java Servlets   «Prev  Next»

Lesson 10

Servlets generate Web Pages Conclusion

What are the key points to know about web page generation using Servlets?

One should now be able to
  1. Generate an entire page of HTML from a servlet
  2. Mix static and generated HTML on the same Web page
  3. Maintain state in a servlet
  4. Include the current time on a Web page
  5. Recognize the HTML that generates a form
  6. Use form data in a servlet

What are the different ways a Java Servlet can generate a page?

A Java Servlet can generate a page in several ways, including:
  1. Using the PrintWriter class to write plain text or HTML to the response.
  2. Using the JSP (JavaServer Pages) technology to create dynamic web pages.
  3. Using the ServletOutputStream class to write binary data to the response.
  4. Using a template engine like Freemarker or Velocity to generate the page from a template.
  5. Forwarding the request to another servlet or JSP page using the RequestDispatcher.
  6. Redirecting the client to another page using the sendRedirect method.

Terms and concepts

This module introduced you to the following key terms and concepts:
  1. escape: An escape character is a way to write a symbol that can not normally be written.
  2. HTTP response:An informational response indicates that the request was received and understood. It is issued on a provisional basis while request processing continues. It alerts the client to wait for a final response. The message consists only of the status line and optional header fields, and is terminated by an empty line.
  3. HTTP request:Whenever your web browser fetches a file (a page, a picture, etc) from a web server, it does so using HTTP, that is "Hypertext Transfer Protocol".
  4. Throw: The throw keyword in Java is used to explicitly throw an exception from a method or any block of code. We can throw either checked or unchecked exception.

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.

Servlets Generate Html - Quiz

Test you knowledge for generating HTML in servlets by clicking on the link below.
Servlets Generate Html - Quiz