How to Get all Request Parameters in Servlet

 Posted On  | Yashwant Chavan 

In this tutorial, You will learn how to Get all Request Parameters in Servlet. Here we see how to send GET and POST request to servlet and print all the request parameters.

Servlet Jsp - Eclipse Project set up

Get all Request Parameters in Servlet - Eclipse Project Setup


Create deployment descriptor (DD) file named as "web.xml" , and put it into "WEB-INF" directory. You can define only one deployment descriptor per web application.

In web.xml file you can declare many servlets. But as of now we have declared only one servlet (HelloController) configuration.

<servlet-name> is mapped <servlet> element to the <servlet-mapping> element.

<servlet-class> is the actual java class e.g.(<servlet-class>com.technicalkeeda.servlet.HelloController</servlet-class>)

<url-pattern> is the request URI mapping (http://localhost:8080/ServletJspExamples/hello)).

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">

Standard servlet declarations

package com.technicalkeeda.servlet;

import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloController extends HttpServlet {
    private static final long serialVersionUID = 1 L;

    public HelloController() {


    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.requestParamters(request, response);

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Calling doPost");
        this.requestParamters(request, response);

    public void requestParamters(HttpServletRequest request, HttpServletResponse response) throws IOException {

        PrintWriter out = response.getWriter();

        Enumeration < String > parameterNames = request.getParameterNames();

        while (parameterNames.hasMoreElements()) {

            String paramName = parameterNames.nextElement();

            String[] values = request.getParameterValues(paramName);
            for (String value: values) {
                out.write(paramName + " :- " + value + " ");





Deploy and Execute

I am using postman to verify the output.

Send GET request

A GET request appends form data to the end of the URL.

GET request parameters

send POST request

A POST request includes form data in the body of request.

POST request parameters

© 2017

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0237 seconds.