As stated in this Oracle documentation:
The @PathParam
and the other parameter-based annotations,
@MatrixParam
, @HeaderParam
, @CookieParam
, @FormParam
obey the
same rules as @QueryParam
. @MatrixParam
extracts information from
URL path segments. @HeaderParam
extracts information from the HTTP
headers. @CookieParam
extracts information from the cookies declared
in cookie related HTTP headers.
Example (drawn from here):
@Path("/books")
public class BookService {
@GET
@Path("{year}")
public Response getBooks(@PathParam("year") String year,
@MatrixParam("author") String author,
@MatrixParam("country") String country) {
return Response
.status(200)
.entity("getBooks is called, year : " + year
+ ", author : " + author + ", country : " + country)
.build();
}
}
See following URI patterns and result:
URI Pattern : “/books/2012/”
getBooks is called, year : 2012, author : null, country : null
URI Pattern : “/books/2012;author=andih”
getBooks is called, year : 2012, author : andih, country : null
URI Pattern : “/books/2012;author=andih;country=germany”
getBooks is called, year : 2012, author : andih, country : germany
URI Pattern : “/books/2012;country=germany;author=andih”
getBooks is called, year : 2012, author : andih, country : germany
For an explanation of the difference you may have a look at
URL matrix parameters vs. request parameters