• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sending large data volumes to a JSP

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a web application that allows a browser client to request data then render it in the browser. Rendering could take a variety of forms.

For this, I have a servlet that on receipt of a request:
1) reads a data file into an object that contains a byte buffer, then
2) adds that object as an attribute to the HttpServletRequest object, then
3) forwards the request to a JSP file for rendering.

This works, but now I want to handle large data volumes. I'm not sure how to go about this.

I considered streaming, but I'm not sure about adding a stream as an attribute to a request. And my stream needs to be an OutputStream for the servlet and an InputStream for the JSP. Would adding a PipedOutputStream attribute to the request allow my JSP to read from it using a PipedInputStream? I understand this is generally used for inter-thread communication, but would it work between servlets?

Or should I go about this completely differently? Should I use a URLConnection to the JSP? But, then I don't see how the JSP would be able to send response back to the browser.

Or??? Any tips or insights would be greatly appreciated! TIA!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the nature and size of the data that has you concerned?
 
Elizabeth Wilson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!

This would both binary and ascii on the order of hundreds of megabytes.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For what purpose would such data be sent to a JSP? I'm having difficulty envisioning how such data would helpful in rendering an HTML view.
 
Elizabeth Wilson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say, rendering ascii data as a table in HTML or as a plot created via a visualization tool called from Javascript.

Or, possibly a download of binary data generated on the fly.

 
Elizabeth Wilson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thinking further about the binary download use case, perhaps HTML would not be involved in that. I should focus on the passage of the ascii data.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's rare to see tables with that much data -- it's just not useful to the user to be inundated with tons and tons of data. Rather, paging and filtering of data is much more useful and prevents sending lots of data to the browser that's likely not even going to be looked at.

As for plots, are you talking about images? Sending binary data to a JSP is not the way to display an embedded image. Rather, you would create an image tag that references a servlet that streams the image data as its response (and sets the appropriate content headers).

In short, it's really never a good idea, or practically necessary, to send any large amount of data to a JSP (which is why you haven't found a ready means to do so).
 
Elizabeth Wilson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I agree about viewing large data tables, though that's the way it has been done around here and there's a
comfort factor for some in seeing it continue to be available that way.

Though, I like the idea of paging, wish I'd thought of that myself. Any clues on how to go about that? Seems like
caching would be needed to allow paging back and forth.

Thanks for the point about the image tag. How about the case where I want to allow the user to click on a link to
download binary data resding in some servlet's memory somewhere?

Okay, will not try to send large amounts of data to JSP. Thank you for the guidance!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Elizabeth Wilson wrote:Though, I like the idea of paging, wish I'd thought of that myself. Any clues on how to go about that? Seems like caching would be needed to allow paging back and forth.

Actually, it's best to let the DB worry about it. Why pull data out of the DB that's not going to be viewed? See the JSP FAQ for a discussion of paging.

Thanks for the point about the image tag. How about the case where I want to allow the user to click on a link to
download binary data resding in some servlet's memory somewhere?

Same deal. You create a link in the JSP. Sending the binary to the JSP is useless -- there's nothing to do with it there. Whether it's an image or a link, it references a servlet that will stream the binary data in the appropriate format.

Okay, will not try to send large amounts of data to JSP. Thank you for the guidance!


It's what the Ranch is here for!
 
Elizabeth Wilson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Actually, it's best to let the DB worry about it. Why pull data out of the DB that's not going to be viewed? See the JSP FAQ for a discussion of paging.



Good point. Will check out that page.

Same deal. You create a link in the JSP. Sending the binary to the JSP is useless -- there's nothing to do with it there. Whether it's an image or a link, it references a servlet that will stream the binary data in the appropriate format.



Yup, okay, got it.

It's what the Ranch is here for!



This has been very helpful! Thanks a bunch!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic