wellnwill

ServletRequest

1. ServletRequest parameters

  • Web client sends data to Web server in request header or body as query string
  • Web container collects this query string data from request header/body and stores in HttpServletRequest object as parameter(s)
  • These parameters and associated values can be fetched using HttpServletRequest object
  • There are mainly three ways to fetch values from these parameters

Using getParameter and getParameterValues

String name = request.getParameter("name");
String jModules[] = request.getParameterValues("jModules");

Using getParameterMap

Map map = request.getParameterMap();
   Set paramNames = map.keySet();
  Iterator it = paramNames.iterator();
  while (it.hasNext()) {
   String paramName = (String) it.next();
   Object paramValue = map.get(paramName);
   String[] paramValueArray = (String[]) paramValue;
   for (int i = 0; i < paramValueArray.length; i++) {
    out.println("");
   }
   out.println("
"); }

Using getParameterNames

Enumeration paramEnum = request.getParameterNames();
   List paramList = Collections.list(paramEnum);
  for (String param : paramList) {
   out.println(request.getParameter(param) + "
"); }
 
Footer with Map

Top