Get all updates of Java4s
Follow Us: Email Newsletter

RESTful Web Services (JAX-RS) @QueryParam Example

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 :-)


  • 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 Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. 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.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

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