• 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

passing large data to a servlet

 
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I'm making some servlets that should be able to plot data.
I have already got them working by passing the parameters like: http://myServer/plot?x=1,2,3,4&y=1,2,3,4
but the problem is that if the data is large (10000 points) then it most likely would fail due to the length limits.
Alternatively, I've tried:



but the code above creates 2 identical images using the second set of values in the session attributes.
Is there a better way?
I'd appreciate any useful comments. Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a POST rather than a GET.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm calling the sevlet from another servlet. The parent servlet is creating a document. The child servlet is creating the image. so how would I send a post request from the parent servlet?
 
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
How are you invoking the second servlet now? And do you really think that's the best design in the first place?
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what's the best way. That's why I'm asking.
The code for parent servlet is like this:


but this is going into the doGet method. I'm not sure how to go to the post method and pass parameters properly to avoid the problem.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One important point: why am I using separate servlets?
That's because the contents of the parent should contain both text and image and that is impossible with a single servlet because the content type can be either image or text.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so your servlet is not calling the other servlet. It's creating an image tag that's referencing the second servlet. So I'll assume that the second servlet responds with image data.

Using the session to hold the data is somewhat problematic -- what if the user opens multiple windows? The data will conflict.

If there is too much data for the image URL, you might place a Map in the session that uses a unique key to identify the data stored as the value. This key could be passed on the image URL. That way, if there are multiple sets of data, they will each have a unique entry in the Map.

 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds pretty good. The key could be just a random number and that multiple windows won't run into problems either. I suppose that I need to cleanup the session attributes (HashMap objects) so I should use a clever attribute name then remove it with the removeAttribute method.
Thanks a lot bear. Please let me know if there are other things that I should consider in the design.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kourosh parsa wrote:I'm calling the sevlet from another servlet. The parent servlet is creating a document. The child servlet is creating the image. so how would I send a post request from the parent servlet?



If both servlets are part of the same application;

- Load data in a value object
- Load the value object as an attribute in the httpservletrequest
- Then forward to the second servlet - there you retrieve the value object and that's it, no long urls and redirect. No session cleanup - the request is garbage collected as soon as the current roundtrip is finished.

D.
 
kourosh parsa
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works pretty well. Awsome.
Now that it works, I should start to think about the memory/speed constrains.

Here is an interesting page for those who are interested: https://coderanch.com/t/525221/Performance/java/Max-size-HttpSession-attribute
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic