wood burning stoves 2.0*
The moose likes Servlets and the fly likes passing large data to a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing large data to a servlet" Watch "passing large data to a servlet" New topic
Author

passing large data to a servlet

kourosh parsa
Ranch Hand

Joined: Jan 22, 2012
Posts: 35
    
    1
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Use a POST rather than a GET.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kourosh parsa
Ranch Hand

Joined: Jan 22, 2012
Posts: 35
    
    1
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Jan 22, 2012
Posts: 35
    
    1
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

Joined: Jan 22, 2012
Posts: 35
    
    1
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

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

Joined: Jan 22, 2012
Posts: 35
    
    1
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.
Daniel Val
Ranch Hand

Joined: Jan 09, 2012
Posts: 44
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

Joined: Jan 22, 2012
Posts: 35
    
    1
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: http://www.coderanch.com/t/525221/Performance/java/Max-size-HttpSession-attribute
 
 
subject: passing large data to a servlet
 
Similar Threads
is null question
using servlet to create a html page with embedded Image
Pagination Problem
Applet(with images) running problem at Client
Checking Loading of image