• 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 data from a servlet to a javascript page

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm currently running into an issue with a project where the time to load the data is taking too long for users. The time it takes to grab the data from the database and send it over to the javascript is fast. The time it takes to process the data on the javascript end is not.

When sending data over, I concat values as such: ("value1|value2|value3||value1|value2|value3..."). Then in the script I split the array based on the deliminator, and I know that the first value is, lets say, the name of the state. Then I know the second value is the number of email opens in that state, etc. I was thinking of doing JSON, but since JSON is based on a key-value system, would that be more data? Since the data I would be sending would be something like: ("stateName{count: value2, stateLongName: value3}").

Is the way JSON parsed faster than concatinating values into a string, then using JavaScript's 'split()' function to split them up as arrays and looping through them?

Thanks for the help!
 
Greenhorn
Posts: 8
1
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't feel that splitting a string or parsing JSON should really take much time on modern hardware and browsers, unless it's a serious ton of data but even then it's more likely what you're doing with the data afterwards. Have you profiled your Javascript so you know for sure where it's spending all of its time?
 
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
Use JSON, not some proprietary format.

Then if there's a performance problem, we can pursue that.
 
Ranch Hand
Posts: 171
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree with Bear Bibeault, use Json....it performs awesome with UI, infact JSON=Java Script Object Notation. JSON is made for javascript and you can use AngularJS to save yopurself from writing JSON parsing code.
***Not trying to promote AngularJS, its just an example, there may be other frameworks too which I am not aware of.
 
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
With modern browsers, JSON is baked right into JavaScript so, in essence, all frameworks, or even using no framework, works well with JSON.
reply
    Bookmark Topic Watch Topic
  • New Topic