1. Download Excel file in JAX-RS
Full example to download an ms excel file from JAX-RS.
package com.dineshonjava.ws.rest; import java.io.File; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; /** * @author Dinesh Rajput * */ @Path("/excel") public class ExcelFileService { private static final String EXCEL_PATH = "d:Contact.xls"; @GET @Path("/get") @Produces("application/vnd.ms-excel") public Response getContactExcelFile() { File file = new File(EXCEL_PATH); ResponseBuilder response = Response.ok((Object) file); response.header("Content-Disposition", "attachment; filename="contact_excel_file.xls""); return response.build(); } }
2. Test
Deploy above JAX-RS service, access this URI pattern : “http://localhost:8181/sdnext/doj/excel/get”.
Figure : MS-Excel file “d:Contact.xls” from server is prompt for user to download, with a new me excel file name “contact_excel_file.xls”
Download SourceCode
Download excel file from JAX-RS.zip
References
1. JAVA REST Web Services
2. Wikipedia for REST Web Service
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…