Get the HTTP request information

After the method declaration, add the request code (in black text below):

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

public class ServletSample extends HttpServlet
{

   public void doGet (HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
   {

      Enumeration keys;
      String key;
      String myName = "";
      keys = request.getParameterNames();
      while (keys.hasMoreElements())
      {
         key = (String) keys.nextElement();
         if (key.equalsIgnoreCase("myName")) myName = request.getParameter(key);	
      }
      System.out.println("Name = ");
      if (myName == "") myName = "Hello";

   }
}

This new section of code handles the client request parameters. The HttpServletRequest class has the following specific methods to retrieve information provided by the client:

In the case of ServletSample, the getParameterNames() method gets the name of the parameters, and the getParameter() method gets the value of the myName parameter.