Skip to main content

MediaType of REST

1 reply [Last post]
wonderqiao
Offline
Joined: 2009-06-17
Points: 0

Hi, I am beginner in REST web services.

I wrote a program of REST to display the HTML or XML. The @Path annotation's value is @Path("{typeDocument}"). There are two methods for GET :
@GET
@Produces(MediaType.TEXT_XML)
public String getXml(@PathParam("typeDocument") String typeDocument)
to display XML file,
and
@GET
@Produces(MediaType.TEXT_HTML)
public String getHtml(@PathParam("typeDocument") String typeDocument)
to display HTML.

The browser Firefox always excutes getHtml() when URL is either http://localhost:8080/sources/html or http://localhost:8080/sources/xml
But IE always excutes getXml().
How to excute the correct method, as defined by URL, in different browser ? Thanks a lot.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
wonderqiao
Offline
Joined: 2009-06-17
Points: 0

I resoved this problem.
I removed @Path from class, and added @Path before each method, as this :

@GET
@Produces(MediaType.TEXT_XML)
@Path("xml")
public String getXml()

@GET
@Produces(MediaType.TEXT_HTML)
@Path("html")
public String getHtml()

Now it runs well.