Example

The following example servlet prints how many times its $\lstinline{service()}$ method was called. Note that $\lstinline{HttpServlet}$ is a subclass of $\lstinline{GenericServlet}$, an implementation of the Servlet interface.

The $\lstinline{service()}$ method of $\lstinline{HttpServlet}$ class dispatches requests to the methods $\lstinline{doGet(), doPost(), doPut(), doDelete()}$, and so on; according to the HTTP request. In the example below $\lstinline{service()}$ is overridden and does not distinguish which HTTP request method it serves.


\begin{lstlisting}
import java.io.IOException;
\par
import javax.servlet.Servlet...
...estroy() {
getServletContext().log(''destroy() called'');
}
}
\end{lstlisting}