I have a ejb3 session bean and a servlet. The bean have access to a database with some big table. The servlet should retrieve the table's content from the bean and send data through ServletOutputStream. How I can transfer big data between ejb3 bean and servlet? I can't return a list with all rows at once because it doesn't fit in memory.
PS. The data are downloaded as a file. They do not appear on a page.
You can transfer large files across the EJB boundary by using the Externalizable inteface (an extension of Serializable). This is what I suggest:
ExternalFile
that wraps/contains a File
object Externalizable
writeExternal
to write the contained file to the given output stream readExternal
to read the given input stream into a new temp file Step 3 is your serializing stage for when you are sending your object (file) from the EJB layer. Step 4 is your de-serializing stage which receives the file as a data-stream and can do whatever it wants with the stream. My 4 suggests writing it to a temp file but you could pass this stream directly via your servlet to any other destination.
Hope that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.