简体   繁体   English

使用Java EE和Primefaces从MySQL下载文件

[英]Downloading a file from MySQL using Java EE and primefaces

Well I have a database with a table that contains a BLOB field, the thing is that I need to make a link to download the files. 好吧,我有一个数据库,该数据库的表包含一个BLOB字段,问题是我需要链接以下载文件。

So far in my backing beans I have a method to generate each record with its respective file, and a method that reads the array of data. 到目前为止,在我的后备Bean中,我有一个方法来生成带有相应文件的每个记录,还有一个读取数据数组的方法。

When I use the P:Datatable to show the records I can view every single record, name and file accesing the file.methods in each one. 当我使用P:Datatable显示记录时,我可以查看每个记录,名称和文件以及每个文件中的file.method。

But I cannot find a way to make it downloadable, I has been searching the forum and the network for away to make something like this 但是我找不到一种可下载的方法,我一直在论坛和网络上搜索以作这样的事情

(listadoArticulos.listado is the array of articles, each article contains a few String fields and a single blob) (listadoArticulos.listado是文章数组,每篇文章都包含一些String字段和一个Blob)

I need to link to the file itself so the user can download it. 我需要链接到文件本身,以便用户下载。

In my backing beans I need to make a method so I can link it, the method has to pass the "File" in the database to bytes (I guess) 在我的后备豆中,我需要制作一个方法以便将其链接,该方法必须将数据库中的“文件”传递给字节(我想)

I will apreciate any help or direction 我会很感激任何帮助或指示

You don't use JSF to generate the file download. 您不使用JSF生成文件下载。 The file download is done directly by a Java handler/servlet, which will set the content-type directly and stream the file content as bytes. 文件下载是由Java处理程序/ servlet直接完成的,它将直接设置content-type并将文件内容作为字节流传输。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM