@Path("/myResource")
@Produces("text/plain")
public class SomeResource {
public String doGetAsPlainText() {
@Produces("text/html")
public String doGetAsHtml() {
The doGetAsPlainText method defaults to the MIME
media type of the @Produces annotation at the class
level. The doGetAsHtml method's @Produces annotation
overrides the class-level @Produces setting, and specifies
that the method can produce HTML rather than plain text.
If a resource class is capable of producing more that one MIME media
type, the resource method chosen will correspond to the most acceptable media
type as declared by the client. More specifically, the Accept header
of the HTTP request declared what is most acceptable. For example if the Accept header is Accept: text/plain, the doGetAsPlainText method will be invoked. Alternatively if the Accept header
is Accept: text/plain;q=0.9, text/html, which declares
that the client can accept media types of text/plain and text/html, but prefers the latter, then the doGetAsHtml method
will be invoked.
More than one media type may be declared in the same @Produces declaration.
The following code example shows how this is done.