Show Topics
Hide Topics

 Download files (text/image/pdf/excel) Using JAX-RS Example

 

We can download any type of files from the RESTful web services, @produces annotation

 

We should annotate our method with

  • @Produces(“text/plain“) If you are expecting Text file as response
  • @Produces(“image/your image type[.jpg/.png/.gif]”) for downloading any Image files
  • @Produces(“application/pdf“) for downloading PDF files

 

 

1.Create Dynamic web project in eclipse, convert that into Maven Project

 

 

2.Add Jersey jar files manually / through Maven by writing repo details in pom.xml

 

 

3.Create RESTFul webservice

 

 

4.Configure web.xml

 

 

5.HTML Page for Download links(index.html)

 

 

6.Test Webservice directly by using URL / writing webservice client

http://localhost:8080/JAXRS-FileDownloads-Example/

 

 

Download Example Code