JAX-RS QueryParam – Jersey

In this tutorial we are going to see about how to pass parameters to RESTful web service via URL using JAX-RS @QueryParam.

Create maven web application project and add Jersey dependency in pom.xml. Find Jersey 2.x maven dependency configuration below. If you are new to maven refer our maven tutorials.

Jersey 2.x dependency in pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <name>RestTutorials Maven Webapp</name>
      <!-- JAX-RS -->
        <!-- Jersey 2.19 -->

QueryParamService .java

package com.ehowtonow.webservice;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

public class QueryParamService {

 public Response getTutorial(@QueryParam("site") String site,
   @QueryParam("tutorial") String tutorial,
   @QueryParam("rank") int rank) {
  return Response
    .entity("Web Site : " + site + "  Tutorial : " + tutorial
      + " Rank : " + rank).build();

In above class JAX-RS @QueryParam annotation used to get the value of URL query parameter into Java Class.

Configure Jersey 2.x Servlet dispatcher

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

	<display-name>Restful Webservice Example</display-name>


Now you can run the service and access the service by calling the following URL


In above URL, the query parameter site=www.ehowtonow.com is access by @QueryParam(“site”) annotation. If you are using query param two times it will converted into list for example tutorial=java&tutorial=stuts will be converted into java.util.List. Checkout the send List to web service using QueryParam Annotation example

Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. File Upload using JAX-RS RESTful Webservice (Jersey 2.x)
  2. JAX-RS @QueryParam with @DefaultValue – Jersey
  3. Download Excel file using JAX-RS RESTful Webservice
  4. JAX-RS @GET RESTful webservice
  5. JAX-RS Web Service to produce XML using JAXB
  6. Restful Webservice HelloWorld Jersey 2.x Example
  7. RESTful Web service to consume JSON and Produce XML – Jersey 1.x
  8. JAX-RS Get HTTP Headers using @Context
  9. Restful Webservice HelloWorld Example Jersey 1.x
  10. Download PDF file using JAX-RS RESTful Webservice
  11. JAX-RS @MatrixParam Restful Webservice
  12. Download Text file using JAX-RS RESTful Webservice
  13. Download image using JAX-RS RESTful Webservice
  14. JAX-RS Get HTTP Headers using @HeaderParam
  15. JAX-RS get QueryParam using @Context UriInfo

Be the first to comment

Leave a Reply