Section 3.5.3, Accessing DB2 via JDBC on page 83 provides a
discussion on accessing DB2 database using the servlet.
Section 3.5.4, Accessing Domino data in Linux with Java on page 93
discusses the way we access a Domino data using the servlet.
3.5.1 Servlets
Servlet is the Java replacement of the cgi programming for Java enabled Web
servers. The servlet can be viewed as a server side Java program that
performs enhanced functions for the Web server. Servlet is implemented
based on the Sun specification that can be found at:
http://java.sun.com/docs/servlet
The following codes are required when creating a servlet:
Creating a Java servlet requires the following imports:
import javax.servlet.*;
import javax.servlet.http.*
The class must extend the HttpServlet class as follows:
public classextends HttpServlet
We must at least implement either the doGet or doPost method.
Therefore, the minimal code required to implement a servlet and service an
HTTP POST request is shown in Figure 65.
import javax.servlet.*;
import javax.servlet.http.*;
public class UselessServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException {
// service POST here
}
}
Figure 65. Minimum code for servlet implementing HTTP GET request
As another example, we want to implement both GET and POST operation
similarly. Since both methods will access the same code base, we
accomplish this by implementing both doGet and doPost and passing the
parameters to another method called doService. This is illustrated by the
code in Figure 66 on page 80.
Chapter 3. Building the Web server
79