LibraryToggle FramesPrintFeedback

When a request is successfully processed the application needs to send a response to acknowledge that the request has been fulfilled. That response may contain an entity.

The most common response when successfully completing a response is OK. An OK response typically contains an entity that corresponds to the request. The Response class has an overloaded ok() method that sets the response status to 200 and adds a supplied entity to the enclosed response builder. There are five versions of the ok() method. The most commonly used variant are:

  • Response.ok()—creates a response with a status of 200 and an empty entity body.

  • Response.ok(java.lang.Object entity)—creates a response with a status of 200, stores the supplied object in the responses entity body, and determines the entities media type by introspecting the object.

Example 4.3 shows an example of creating a response with an OK status.

For cases where the requester is not expecting an entity body, it may be more appropriate to send a 204 No Content status instead of an 200 OK status. The Response.noContent() method will create an appropriate response object.

Example 4.4 shows an example of creating a response with an 204 status.

The Response class provides methods for handling three of the redirection response statuses.

Example 4.5 shows an example of creating a response with an 304 status.

Comments powered by Disqus