JAX-RS (REST)No Comments

In this tutorial, we show you two ways to get HTTP request header in JAX-RS :

  1. Inject directly with @HeaderParam
  2. Pragmatically via @Context
Refer to this wiki page for list of the HTTP header fields.
  • @HeaderParam Example

In this example, it gets the browser “user-agent” from request header.

Access via URI pattern “/users/get“, with FireFox, see following result :

  • @Context Example

Alternatively, you can use @Context to get “javax.ws.rs.core.HttpHeaders” directly, see equivalent version to get browser “user-agent“.

Access via URI pattern “/users/get“, with Google Chrome, see following result :

List all request headers
You can list all available HTTP request headers via following code :

Be the first to post a comment.

Add a comment