Monday, June 25, 2018

Reading Form Data using Servlet


Servlets handles form data parsing automatically using the following methods depending on the situation:
  • getParameter()
  • getParameterValues()
  • getParameterNames()

getParameter() :
      Used to get the value of a form parameter.
                 String paramvalue = request.getParameter("param_name"); 

getParameterValues():
       Used to get the parameter appears more than once and returns multiple values, for example checkbox.
                 String[] paramValues = request.getParameterValues(paramName);

getParameterNames():
        Used to get the complete list of all parameters in the current request.
                  Enumeration paramNames = request.getParameterNames();
                  while(paramNames.hasMoreElements()) {
                            String paramName = (String)paramNames.nextElement();
                   }

 

No comments:

Post a Comment