FileDocCategorySizeDatePackage
HelloWorld.javaAPI DocExample1616Tue Feb 28 11:34:06 GMT 2006None

HelloWorld

public class HelloWorld extends HttpServlet
This is a simple Hello World servlet example to show the main servlet methods.
author
Hans Bergsten, Gefion software
version
1.0

Fields Summary
private String
greeting
Constructors Summary
Methods Summary
public voiddestroy()
This method is called once by the container just before the servlet is taken out of service. In this example, the method resets the servlet instance variable.

      greeting = null;
    
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
This method is called by the container for each GET request. In this example, the method writes a line of text to the response body.


        PrintWriter out = response.getWriter();
        out.println(greeting);
    
public voidinit()
This method is called once by the container when the servlet is initialized, before any requests are delivered to the servlet. In this example, the method reads a servlet init parameter value and saves it in an instance variable. If the parameter is not found, a default value is saved instead.

        ServletConfig config = getServletConfig();
        greeting = config.getInitParameter("greeting");
        if (greeting == null) {
          greeting = "Hello World!";
        }