Servlet HTTP Request Parameters Example

In the previous post, you are similar to the Servlet Context Parameter Example. This tutorial will show you how to build servlet HTTP request parameters example. The HTTP request parameters are passed along with the request. The HTTP request parameters could be passed by two ways. One way is sent as part of the URL and another way is sent as part of of the body of an HTTP request. This is fifth post of series of Java Servlet Tutorial. This series tutorial will provide you full knowledge about Servlet 3.0.

Table of contents:
1. Project structure
2. Maven Dependency
3. Servlet HTTP Request Parameters
4. Deploy Servlet HTTP Request Parameters Example

Project structure

Servlet HTTP RequestParameters Example
Servlet HTTP RequestParameters Example

Maven Dependency

Servlet HTTP Request Parameters
The request.getParameter() method is used to get the HTTP request parameters from the request and returns a string or return null if the parameter doesn’t exist. We can also get an array of parameters with request.getParameterValues() which returns an array of strings.

How to work with array of parameters in Servlet
If you pass the request parameters via URL you will type input on URL such as:
URL: …/servlet-param/param?profileArray=US&profileArray=California

String[] profileArray= req.getParameterValues(“profileArray”);

Deploy Servlet HTTP Request Parameters Example
Here, we deploy file war on application server Tomcat 8 then access the address below

The URL is without parameters: http://localhost:8080/servlet-param/param
We will not receive any Servlet HTTP Request Parameters, here is the result.

Servlet HTTP Request Parameters Example without parameters

The URL is with parameters: http://localhost:8080/servlet-param/param?username=javabycode&password=123&profileArray=US&profileArray=California
We will receive all Servlet HTTP Request Parameters, Here is the result

Servlet HTTP Request Parameters Example deploy
Servlet HTTP Request Parameters Example deploy

That’s all. You can also find other servlet example in the series of Java Servlet Example.

Download complete source code, please click link below

Servlet-Parameters-Example.zip (32 downloads)

Happy leanrning!

Leave a Comment

*

Please share it if you found this useful
Hide Buttons