Example: Java servlet

This example servlet returns an HTML page that displays all the HTTP headers that the browser sent with the servlet request.

import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ExampleServlet extends HttpServlet {

   public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException
{
   response.setContentType("text/html");
   ServletOutputStream out = response.getOutputStream();
   
   out.println("<HTML><B>Headers sent with the request:</B><BR>");

   for (Enumeration headers = request.getHeaderNames();
   headers.hasMoreElements();)
   {
      String headerName = (String) headers.nextElement();
      out.println("<BR>" + headerName + ": " +
      request.getHeader(headerName));
   }
    
} // end of method
} // end of class

After you compile this code, copy the ExampleServlet.class file to your server domino\servlet directory. It does not need any special properties, so you do not need to create a servlets.properties file. Run the servlet from a browser by entering this URL, using the name of your server:

http://www.yourserver.com/servlet/ExampleServlet

The information in the page returned by the servlet depends on the browser.