2012-01-16 51 views
1

我正在使用RestEasy,當我輸入網址http://localhost:8080/resteasy/xml我想在Firefox中看到「另存爲...」選項。無法找到適用於媒體類型的JAXBContext:application/octet-stream

@GET 
@Path("/xml") 
@Produces("application/octet-stream") 
public List<FileDetail> getXmlContent() { 
    return findXml(); 
} 

但是,當我用這個,我得到的錯誤:

Unable to find JAXBContext for media type: application/octet-stream

有什麼不對?

感謝您的幫助。

回答

0

如果想要「另存爲」對話框出現在瀏覽器,你可以在響應加Content-Disposition -header

@Path("/") 
public class Service { 
    @Context HttpResponse response; 

    @GET 
    @Path("/xml") 
    @Produces(MediaType.APPLICATION_XML) 
    public List<FileDetail> getXmlContent() { 
     response.getOutputHeaders().putSingle("Content-Disposition", "attachment; filename=list.xml"); 

     List<FileDetail> data = new ArrayList<FileDetail>(); 
     data.add(new FileDetail()); 

     return data; 
    } 
} 
相關問題