• 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

Javascript Vs JSP Loops

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I was asked this questions in an interview.

Which is one is best. Javascript looping to iterate through collection or use JSTL/any framework provided/for/while loops to loop through the collection to display information onto the browser.

At that point of fact I could not answer to that properly.
I was thinking in terms of code size of the JSP because of its 64K limitation and Client browser setting when Javascript looping is used.

Thinking more and more of it, I feel Using JSP looping is better than Javascript.

Person who interviewed me says that the javascript code is much simpler to maintain and on time scale it is more faster than using java looping.

But I think using Java looping makes code simple and easer to maintain. May be first page will take time to load but subsequent page will be loaded faster.

It is not that I don't want to use javascript at all. I want to use it where I want to populate select option on selection of other form field or something like that.

I was wondering if I am missing something.

Please share your thoughts.
Thank you
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean javascript, or java "scriptlet" code on a jsp (ie java code between <% and %>

javascript can not loop through a java collection.
You would have to download all the data to the client side, as javascript and then execute the loop on the client. That makes for some major processing on the client, and javascript can be comparatively slow to compile and run on the fly.

Using java code in a JSP with <% %> tags, you can use a standard for loop.
But that introduces scriptlet code into your JSP, which makes it harder to maintain.

You can use tag-based loops (eg JSTL forEach tag)
That has the benefit of being plain text in the jsp file. I find them much easier to understand and work with than scriptlet code. But it is less efficient than the pure scriptlet loop.
 
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
While I generally balk at "which is best" type of question since such issues usually require a great deal of knowledge about the problem space, and usually end up being a subjective call in any case, I had to smirk at

Person who interviewed me says that the javascript code is much simpler to maintain and on time scale it is more faster than using java looping.



Few people would agree that JS is simpler to maintain than Java -- I usually find it quite the opposite -- but in regards to "time savings", I wonder in what world it saves time to send a bunch of data over the network to be lopped over by interpeted code in the browser rather than not including it on the rendered page in the first place using server-side Java.
 
s penumudi
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you Bear.
I really appreciate your responses
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic