JAX – RS Different Files Download Example In Jersey

In this tutorial we will learn how to develop JAX – RS Restful application to download different files.

First we see how to download text file example .

Text File download example

——————————————————————————————————————————–

1. Create Dynamic web project in Eclipse.

Restfulfiledownloadexample_proj

2. Write Java Resource classes.

 

3. Configure the Jersey Servlet in web.xml

 

4. Run the Example 

After Deploying the application access the url http://localhost:8080/RestfulFileDownloadExample/    and click on “Click Here to Download File” , so the below File Download window will appear.

 

OUT PUT:

Restfulfiledownloadexample1

 

NOTE : I have not included all the required jersey jars in the source code please download it from here and copy to lib folder.

 

Download  Source Code

 

Excel File download example

——————————————————————————————————————————–

if you want to down load excel file then our resource class will like as below.

juts change the @Produces mimetype and response header properties.

 

Image File download example

——————————————————————————————————————————–

if you want to down load image file then our resource class will like as below.

juts change the @Produces mime type  and response header properties.

 

 

PDF File download example

——————————————————————————————————————————–

if you want to down load image file then our resource class will like as below.

juts change the @Produces mime type and response header properties.

 

 

Happy learning ……….. :)

Posted in jax-rs and tagged , .

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">