Java Servlets   «Prev  Next»

Lesson 10Java Servlets answer via GET requests
Objective Methods to Override a Servlet to Provide HTML.

Methods to override in a Servlet to produce HTML

Explain which method you override in a servlet to provide HTML.
You could open your text editor right now and write a servlet. It would look like this:

public class MyServlet 
extends javax.servlet.http.HttpServlet{
// methods go here
}

The only problem is that a servlet like that does not do anything.
In order to write a useful one, you will have to learn the methods of HttpServlet, so you can recognize which methods to override, just as you did with applets.
The most important one is doGet().
At the very beginning of this module, you learned that when a Web browser wants a file from a Web server, it sends a GET request. If the browser was requesting a specific servlet by name, the Web server would call that servlet’s doGet() method as part of handling the GET request.

You add code to doGet() that writes out HTML, and that is a useful servlet.
Before you start typing code, there is some setup work to do. You need to install the Java Servlet Development Kit (if you do not have it installed already), so that you have the javax.servlet.http.HttpServlet class to extend. You also need to install a Web server that supports servlets, so that you can test your work. You’ll do those tasks and more in the next module.
The next lesson is the module conclusion and reviews key terms and concepts.