get Request Map from HttpServletRequest - Java Servlet JSP

Java examples for Servlet JSP:Servlet

Description

get Request Map from HttpServletRequest

Demo Code


import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Main{
    //from ww w.  j a  v  a  2 s. c om
    public static Map<String, String> getRequestMap(
            HttpServletRequest request) {
        Map<String, String> params = new HashMap<String, String>();
        Enumeration<String> parameters = request.getParameterNames();
        while (parameters.hasMoreElements()) {
            String key = parameters.nextElement();
            String value = request.getParameter(key);
            value = value == null ? "" : value;
            params.put(key, value);
        }
        return params;
    }
}

Related Tutorials