您的位置:首页 > 数据库 > Oracle

根据标题后缀名传参点击下载保存内容为任意格式文件(内容为oracle库中某字段值:BLOB类型)

2012-12-07 09:15 615 查看
jsp页面:



页面列表点击下载,根据下载文件名称后缀名,传参数,下载文件的ID,调用js,到struts中.do处理类。



java类:

@RequestMapping(params = "method=downloadFile")

public void downloadFile(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType(CONTENT_TYPE);

// 解决中文乱码问题

String id = new String(request.getParameter("id").getBytes("iso-8859-1"), "UTF-8");

Long idL = Long.parseLong(id);

DownloadFile downloadFile = downloadFileService.get(idL);

String name = downloadFile.getName();//下载文件名称

byte[] content= downloadFile.getContent();//下载文件内容

response.setContentType("application/x-msdownload ");

response.setHeader("Content-Disposition", "attachment;filename="

+ new String(name.getBytes("gbk"), "iso-8859-1"));

response.getOutputStream().write(content);            // 写入文件

response.getOutputStream().flush();

response.getOutputStream().close();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐