Java – How To Get All Parameters From URL in Servlet

In this post, we show you how to get all parameter values from URL in Java Servlet.

To do this, we can use request.getParameterMap().keySet() to get all parameter names, and then iterate over these parameter names and get its value.

Let’s take a look at the following code to see how it works.
package com.bytenota;

import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "PostServlet", urlPatterns = {"/post"})
public class PostServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        // get all parameter names
        Set<String> paramNames = request.getParameterMap().keySet();
        // iterating over parameter names and get its value
        for (String name : paramNames) {
            String value = request.getParameter(name);
            out.write(name + ": " + value);


Get all parameter names in Java Servlet