This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Passing huge string to JSP..

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Friends,
I am tring to pass a huge string from JavaScript to the JSP page. But it is giving runtime script error. This might be due the limited data you can send through GET method.
Can somebody tell me the way to pass this huge string. I don't want to use POST method as I don't want to create a form in my JSP.
Your views and suggestions will be very helpful...
Thanks
Shikhar
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shikhar,
If the cause of your problem really is that the size of your string is above the GET limit, then there is no way around using POST instead of GET. Why don't you want to create a form in your JSP page?
-Mirko
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shikhar singh:
I am tring to pass a huge string from JavaScript to the JSP page. But it is giving runtime script error. This might be due the limited data you can send through GET method.


Mirko is right. If you exceed the GET limitations, then it's either POST or you don't pass the string at all.
You don't give any context but there's usually no reason to pass a large string like that (apart from forms, but then you could POST). If nothing else, you could store a Map in the user#s session object that maps a short ID to the long string you want to pass. The request then passes this ID rather than the full string.
This is just an illustration, if you start storing response information in the session there's likely to be a more elegant way.
- Peter
 
shikhar singh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mirko and Peter,
Thanks for responding..
Actually In my application, while loading, I populates a javaobject with all data which I want to display to the user. Then I converts this object into a string which contains the data. I passes this huge string (which contains most most of the data which I want to display to client) to JavaScript (after encoding). In java script I decodes this string and converts this back to Javascript object.
Now for a particular operation (sorting the data, in my case), I want to pass this object back to JSP to do manipulation.
So, as you said I should use POST, what will b the syntax in JavaScript to POST this data to JSP.
I desperately need a solution..your views and suggestions will be very useful.
Thanks
Shikhar
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shikhar singh:
Actually In my application, while loading, I populates a javaobject with all data which I want to display to the user. Then I converts this object into a string which contains the data. I passes this huge string (which contains most most of the data which I want to display to client) to JavaScript (after encoding). In java script I decodes this string and converts this back to Javascript object.
Now for a particular operation (sorting the data, in my case), I want to pass this object back to JSP to do manipulation.


Since the data was generated by a JSP in the first place, it could presumably be generated again. If that is an expensive operation, you could leave it bound in the session (it can't be THAT huge). So all you would have to send in your request is how you want the thing to be sorted, no?
- Peter
 
shikhar singh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,
Thanks for your suggestion
Actually, I had the same idea as you've given. But actually let me explain the problem:
My application is a email management system. Emails from a single customer are grouped together to form a 'ticket'. Person using this application can have 100-150 tickets(i.e. 100*(2or 3) emails)... So you can imagine how big the object is. Now each user will have his own mailBox. So if I hold this object in session at server side, and if the number of users are high, (say 50-100), the load on the server will be tremendous.
Thats why, I prefered to pass the object back to JSP, sort it and send it back to Javascript.
1. I don't want to do in Javascript , as this will be a huge processing at client.
2. I don't want to fire the query again to get the sorted information, as this will try to un-necessarily try to fetch the data again which we already have. This will also incrase the load on server.
Can you just tell me how to pass this huge object from JavaScript to JSP, with the help of POST or any other way....
thanks
Shikhar
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shikar,
If you do not want to use the post method, another alternative is to put the strign into a session object and call the session object in which ever page you want to....and if you are using the string in the next called page then you can destroy the session object after getting the string value...
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by shikhar singh:
My application is a email management system. Emails from a single customer are grouped together to form a 'ticket'. Person using this application can have 100-150 tickets(i.e. 100*(2or 3) emails)... So you can imagine how big the object is. Now each user will have his own mailBox. So if I hold this object in session at server side, and if the number of users are high, (say 50-100), the load on the server will be tremendous.


Sanity check. What's the memory footprint of your average e-mail object? 10KB (finger in the air, should check)? 300 e-mails per user, 100 users, that's 300MB of memory. A well-equipped box could handle that on its own, but I understand your worries.

Thats why, I prefered to pass the object back to JSP, sort it and send it back to Javascript.
1. I don't want to do in Javascript , as this will be a huge processing at client.
2. I don't want to fire the query again to get the sorted information, as this will try to un-necessarily try to fetch the data again which we already have. This will also incrase the load on server.


1. Agreed. My own experiences with attempts to handle any amount of data in JavaScript were... ahhh... not happy.
2. Did you consider the network and request parsing load caused by clients sending over such massive amounts of data? Not to mention the clients' waiting time, especially if they're on dial-up lines (remember that these are often asymmetric, i.e. the request transfers slower than the response).
Personally I still think the request just should specify the sorting order. Initially, I'd just do the query again and see how it performs (if it ain't broke, don't fix it). If database load is a problem, I'd code a simple global LRU cache that will retain the e-mails for a fixed number of users. That should take most of the load off your database without melting your server.

Can you just tell me how to pass this huge object from JavaScript to JSP, with the help of POST or any other way....


Naaah, a discussion at this level is more fun But if you want to stick with your approach, it's going to be a POST, and therefore a form. Maybe you use JavaScript to submit the form from an ordinary link so that it doesn't look like a form? (Is that possible at all? Don't know, never had reason to do that).
- Peter

[This message has been edited by Peter den Haan (edited February 02, 2001).]
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shikhar,
We can send a composed huge String from JavaScript to Jsp/Servlet. I checked this. Please see the foll. code.

In the Servlet/jsp where this form is submitted to, grab the hidden huge string as follows.

regds
maha anna
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with peter that the network bandwidth is too great to pass the emails back and forth for sorting only purposes. Imagine that in peter's example all 100 users login in decided to change their view of the email in less than 5 minutes.300MB in an initial sort order, 300MB from the client to the server to change the order,and then 300MB back to the clients in the desired order = 900MB/5min= (900*8)/300=24mbs. You would need a pretty beefy connection otherwise this could slow the response time down to a crawl and in the worse case could crash the server. HTML is a thin client so almost all of the work should be done on the server side. I do not see why re-running the query again is such a bad idea. The database would be much more efficient in sorting and storing the data than the application server, especially if indexed. Also is it necessary to display all of the emails at the same time? Why not limit it to 25 or so. This would make things MUCH more manageable.
 
shikhar singh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
Thanks for yor precious advices..
I am trying to implement Maha Ana's suggestion.
Aaron, you asked why I want to display all the emails at a time. Actually, It is just like Microsoft Outlook, where the summary (date, subject, sender's address..etc ) is displayed to the user.
Now whent eh first time the user logs in I use to fetch all these summaries in a object and pass it to client. So, my problem is, if the client wants to sort the tickets(you can imagine it as an email), should I do it in JavaScript.
I already implemented this thing in JavaScript by using Quick Sort algorithm. I tried this with 100 tickets/emails, and it the speed is acceptable.
According to Aaron's idea, I've decided to display few emails at a time(in our case 100-150).
Can anybody tell me that is this a bad approach or this can cause some problem of any sort.
I'll also try Maha Ana's idea to POST the string to JSP, sort it and send it back to the client.
Moreover I don't want to fire a query to the database(to get sorted data), coz I'm already holding this data on client side and useing this for other operations (like caching the content of the email).
Thanks again all of you for your precious time and advices...
shikhar
 
pie. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic