Get all updates of Java4s

RESTful Web Services (JAX-RS) @PathParam Example

In RESTful (JAX-RS) web services @PathParam annotation will be used to bind RESTful URL parameter values to the method arguments. Lets discuss with a simple example.

If you are new to RESTful web services or if you would like to know complete step by step flow of JAX-RS, Go through this article ‘Jersey Hello World example With Maven in Eclipse Juno‘, then only you will be able to understand this tutorial :-) and even further web services tutorials.

Required Files

  • pom.xml
  • web.xml




  • Right click on your project > Run As > Run on Server
  • By default eclipse will open http://localhost:2013/RestPathParamAnnotationExample/ with  HTTP 404 Error
  • In web.xml we have specified URL pattern as /rest/* (line number 19) and in we specified class level @path as /customers [ line number 9 ] and method level @path as  {name}/{country} [ line number 13 ]
  • So the final URL should be http://localhost:2013/RestPathParamAnnotationExample/rest/customers/Java4s/USA
  • Once you hit the URL,  http://localhost:2013/……/rest/../Java4s/USA  , last two parameters in this URL ‘Java4s‘ and ‘USA‘ are retrieved by @PathParam(“name”), @PathParam(“country”) annotations in and will copy into String name, String country respectively.
  • Check the output


You Might Also Like


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

    Really an understandable explanation

  2. Sourajya says:

    Can you please explain me the use of init-param here?

    The values you have provided under param-name and param-value tags, I can’t understand.

  3. Aakash Ahmed says:

    Sivateja Kandula Your Really Done WonderFull Job And Keep It Up..!

  4. vijay says:


    this is vijay, please help me . i want to send JSON data as request to REST web service and want to store JSON element to data base and response to client as successful read json elements.

  5. mohit says:

    hello, this is mohit .please help me i want to create request in xml format and then that xml send as request with url, and want to get back response in xml format

  6. Hello sir,

    Nice and superb explanation !!!!!!!!!!!


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Spring-Boot-tutorials Hibernate tutorials Spring tutorials Struts tutorials Servlets tutorials Ajax tutorials Log4j tutorials jQuery tutorials Json tutorials Core Java tutorials Web Services tutorials AngularJs tutorials
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
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.