1. Form parameters are key-value pairs where both key and value are String objects only.
  2. A form parameter can be associated with single value or multiple values.
  3. HttpServletRequest interface defines the following methods to retrieve form parameters at server side
    • getParameter(String name)
    • getParameterValues(String name)
    • getParameterNames()
    • getParameterMap()

getParameter(String name)

    public String getParameter(String name)

  1. Returns the value associated with specified form parameter
  2. If the parameter associated with multiple values then this method returns only first value
  3. If the specified parameter is not available then it returns null
  4. Argument is case sensitive.
  5. Example:

    String name=request.getParameter("uname");
    

getParameterValues(String name)

    public String[] getParameterValues(String name)

  1. It returns all values associated with specified form parameter
  2. If the parameter associated with multiple values then this method returns only first value
  3. If the specified parameter is not available then it returns null
  4. Argument is case sensitive.
  5. Example:

    String[] courses=request.getParameterValues("course");
    for(String course:courses){
     out.println(course);
    }
    

getParameterNames()

    public Enumeration getParameterNames()

  1. It returns enumeration of all form parameter names
  2. If the request doesn’t associated with any request parameter then this method returns empty Enumeration object but not null
  3. Example:

    Enumeration e=request.getParameterNames();
    while(e.hasMoreElements()){
     String name=(String)e.nextElement();
     String value=request.getParameter(name);
     out.println(name+"----"+value);
    }

getParameterMap()

    public Map getParameterMap()

  1. It returns the parameter names and parameter values in Map form
  2. Parameter names are keys, which are String objects.Parameter values are Map values,which are String array
  3. Example:

    Map<String, String[]> m = req.getParameterMap();
      for (Map.Entry<String, String[]> e1 : m.entrySet()) {
    	String vname = (String) e1.getKey();
    	String[] values = (String[]) e1.getValue();
    	out.print(vname);
    	for (String s1 : values) {
        	    out.println(s1);
    	}
      }