to the main page about the tutorial  INTERACTIVE WEB SERVICES WITH JAVA back up next

Introduction

Servlets are written in pure Java using the Servlet API:

"Hello World" in Servlets:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet 
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html><head><title>Servlet</title></head>");
        out.println("<body><h1>Hello World!</h1>");
        out.println("This page was last updated: " + new java.util.Date());
        out.println("</body></html>");
    }
}

Useful methods in HttpServlet to be implemented in sub-classes:

Useful predefined methods:

Exceptions: ServletException

back COPYRIGHT © 2002-2003 ANDERS MØLLER & MICHAEL I. SCHWARTZBACH next