RESTful Web Services (JAX-RS) @QueryParam Example

Web Services » on Jul 8, 2014 { 6 Comments } By Sivateja

In RESTful web services (JAX-RS) @QueryParam annotation will be used to get the query parameters from the URL, Observe carefully, i am saying we will retrieve the parameters only not their values.  But in case of @PathParam we will get parameter values directly.

Query Parameters Syntax

Consider this URL:
Here query parameters are nameKey, countryKey and their values are Java4s, USA respectively, hope you understood.

Required Files

  • pom.xml & web.xml are similar to previous article no changes 🙂

package com.java4s;
public class RestServiceQueryParamJava4s {
    public Response getResultByPassingValue(
                    @QueryParam("nameKey") String name,
                    @QueryParam("countryKey") String country) {
        String output = "Customer name - "+name+", Country - "+country+"";
        return Response.status(200).entity(output).build();


  • Right click on your project folder > Run As > Run on Server
  • Eclipse will open http://localhost:2013/RestQueryParamAnnotationExample/ with  HTTP 404 Error
  • In web.xml we have specified the url pattern as /rest/* (line number 19) and in we specified class level @path as /customers [ line number 9 ] and we are retrieving 2 query parameters [ Line number 15,16 ], so our final URL should be the http://localhost:2013/RestQueryParamAnnotationExample/rest/customers?nameKey=java4s&countryKey=USA
  • Check the output by hitting the above URL



You Might Also Like

  ::. About the Author .::

Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


6 Responses to “RESTful Web Services (JAX-RS) @QueryParam Example”
  1. satish says:


    Sivateja Garu,your examples and explanation is very nice,this is very right tutorial for beginners.
    But we need JSON resource from rest service and also we all looking soap based web service.


  2. Java4s says:


    We will finish JAX-RS by end of this week, this will cover everything including JSON resource style.


  3. Arunkumar Papena says:

    Am getting “HTTP Status 500 – Servlet.init() for servlet jersey-serlvet threw exception” when i try to use @QueryParam. And it is working fine for @PathParam.

    What i need to do?

  4. SatishReddy says:

    Hi Sive,
    Thank u very much for make me a clean understanding of ur tutorials .
    I start to learn angualr js.
    I need a small example in angular js with image upload and display the uploaded image download.
    Waiting for u r response.
    Thanks & Regards
    Satish Marutham

  5. Siva says:


    We are currently working on completing the AngularJS, yep definitely we will consider this scenario and post an article on it.

  6. kumar says:

    hi anna how to retreving image from my sql database in java with jdbc code send example pze anna


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.