Edit Edit

Java Servlet FAQ

What does a simple Hello World-servlet look like?

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

public class HelloWorld extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                      throws ServletException, IOException

       // set the content type
       PrintWriter out = res.getWriter();

       // output the HTML that displays "Hello World"
       out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
       out.println("Hello World!");

Last updated 01/03/2000 10:38:02 PM