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:
http://localhost:2013/RestPathAnnotationExample/rest/customers?nameKey=Java4s&countryKey=USA
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 :-)
  • RestServiceQueryParamJava4s.java

RestServiceQueryParamJava4s.java

Explanation

  • 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 RestServiceQueryParamJava4s.java 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

Output

You Might Also Like

  ::. About the Author .::

Java4s_Author
- Full Stack Java/J2EE & UI Web 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.

Comments

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

    Hai,

    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.

    thanks&regards,
    Satish.

  2. Java4s says:

    @Satish

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

    -Siva

  3. Arunkumar Papena says:

    Hi,
    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?
    -Thanks.

  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:

    @SatishReddy,

    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

Name*
Mail*
Website



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

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