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
       res.setContentType("text/html");
       PrintWriter out = res.getWriter();

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



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