Download excel file from JAX-RS
2015-08-27 11:48
351 查看
In JAX-RS, for excel file, annotate the method with
Put
Set “
Figure : Excel file “
@Produces("application/vnd.ms-excel"):
Put
@Produces(“application/vnd.ms-excel”)on service method.
Set “
Content-Disposition” in Response header to prompt a download box.
1. Download Excel file in JAX-RS
Full example to download an excel file from JAX-RS.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; @Path("/excel") public class ExcelService { private static final String FILE_PATH = "c:\\excel-file.xls"; @GET @Path("/get") @Produces("application/vnd.ms-excel") public Response getFile() { File file = new File(FILE_PATH); ResponseBuilder response = Response.ok((Object) file); response.header("Content-Disposition", "attachment; filename=new-excel-file.xls"); return response.build(); } }
2. Demo
Access this URI pattern : “/excel/get“.
Figure : Excel file “
c:\\excel-file.xls” from server is prompted for user to download, with a new file name “
new-excel-file.xls“
相关文章推荐
- C++ Explicit Constructors(显式构造函数)
- spm打seajs压缩包摘抄
- Android UI设计——Spinner控件
- Job流程:Shuffle详解
- SAP的战略企业管理功能介绍
- 如何把pdf转换成txt格式的文件
- Chapter 10. Generic Algorithms
- u启动u盘启动盘制作工具制作U盘启动盘教程
- ImageLoder的简单使用
- java-captcha实现验证码(二)
- import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport;这两行报错
- Cmake——CMake+SVN或Hg生成版本号
- 每个人都应该懂点函数式编程
- 【学习笔记2】Logistic Regression
- C语言中正切的相关函数总结
- demo2 JAVA变量
- 手持移动端特殊链接:打电话,发短信,发邮件
- 【Memphis】非旋转Treap及可持久化[Merge,Split]
- 3D动画
- oldssoj2676B(环)