2 Minutes To Code (β Version)

Java Servlets - 2 minute tutorial

How to get parameters sent by http client from HttpServletRequest

To get the parameters that the http client sends with the http request, you use the method String getParameter(String) of the HttpServletRequest object as shown in the example below.

If the parameters has multiple values (like in the case of a multi-valued select dropdown of a form element), then you can use the method String[] getParameterValues(String).

To get the names of all parameters, you can use the method Enumeration<String> getParameterNames().

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	String userName = req.getParameter("user");
	String[] hobbies = req.getParameterValues("hobbies");
	Enumeration<String> paramNames = req.getParameterNames();
	Map paramMap = req.getParameterMap();