RESTful Web Services (JAX-RS) @MatrixParam Example

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

In this article i will describe how a RESTful web services would accept multiple parameters sent by the client in the HTTP URL as Matrix Params. So what are matrix parameters ? let me give you the syntax.

Matrix Parameters Syntax

Consider this URL

If you observe the URL, i am passing 2 parameters nameKey=Java4s & countryKey=USA.  One parameter is separated from another with a semicolon, similarly you can pass any number of parameters. These type of parameters are called as Matrix Parameters. I will explain more about matrix parameters in this example.

Required Files

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


  • Once you run the application,  eclipse will open the following URL  http://localhost:2013/RestMatrixParamAnnotationExample/   by default
  • In [ line number 9 ] we have given class level path as /customers and we are using @MatrixParam annotation to retrieve the client inputs from the URL, so the final URL should be



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.


4 Responses to “RESTful Web Services (JAX-RS) @MatrixParam Example”
  1. vishwnath says:

    Nicely explaiined Web Services !!!

  2. PugaZhendhi says:

    Nice Tutorial. But we need interview point of question.

  3. Rabindra says:

    Can you please discuss the functional difference of MatrixParam and QueryParam?

  4. Prakhar says:


    Can you explain one example to upload files using jQuery and also retrieving for the same.


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.