4576l2

Listing 2: HelloWorld.java, a simple applet that handles the GET
request method

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

public class HelloWorld extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        // Set the MIME content type for the response
        response.setContentType("text/html");

        // Get the output stream to STDOUT
        PrintWriter out = response.getWriter();

        // Print some HTML
        out.println("<HTML>");
        out.println("<Head><Title>Hello, world</Title></Head>");
        out.println("<Body>");
        out.println("<P>Hello, world</P>");

        // Get the user's first name, if he or she passed it to us
        String firstname = request.getParameter("firstname");

        // Print a special greeting for people who give us their name
        if (firstname != null) 
            {
                out.println("<P>Your first name is \"" + firstname + "\"</P>");
            }

        // Finish the HTML
        out.println("</Body></HTML>");
    }
}

