• 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

Iterating through local List using JSTL

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i have once jstl in which i have created java.util.List and adding three element.

And now when i am trying to iterate through the list using jstl forEach loop, i am not able to retrive any element.

Bellow is the complete code .jsp file, Help me out solving this issue.


Regards,
 
Sheriff
Posts: 67752
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
At what point do you create a scoped variable named list? (Answer: you don't.)
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
line no 17 is not required anymore i just added it for testing whether the EL is working fine or not






Line 25 in items i m getting the list which is of type java.util.List items="${list }">

and assisgnig it to variable listItems for iteration var="listItems"



 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just change this part of your code
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah i have changed it

new code



and the bellow is the output in browser




Welcome to JSTL

--------------------------------------------------------------------------------
List Size : 3
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And take a look at the For loop (JSTL).
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the scope List list?
Where it will look for list?
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
list is an local variable i am just creating it before iterating

 
Bear Bibeault
Sheriff
Posts: 67752
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
Why would you expect the JSTL/EL, which are meant to replace scriptlets to know anything about scripting variables?

It doesn't.

You need to create a scoped variable for the EL to be able to access the data.

I assumed that the scriptlet code was in this JSP for testing purposes only. You wouldn't really put scriptlets in a JSP, would you?
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jigar, you don't see the desired output because list is out of scope for the loop.
Try putting List list into request and see what happens?

And take in account Bear's advice. Don't use Scriplets.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yup i won't use scriptlets anymore.. but it worked with request scope... i was trying an example...
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jigar Naik wrote:yup i won't use scriptlets anymore.. but it worked with request scope... i was trying an example...


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

yup i won't use scriptlets anymore.. but it worked with request scope... i was trying an example..


Here you have used the scope to access/iterate the List - would you please post the code you used.

I am trying to set it using (I dun know how to do it using JSTL tags )and then trying to access it on the same page as well as some other forwarded page(on submit of a form)But that is not helping. And I am getting this error -the mysterious and cryptic error. Thanks in advance.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




 
Shashank Rudra
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Naik for the quick response. But still I am helpless. here are the jsps that I am trying to test this on

The first JSPHere I am setting the request parameter and then submitting to the testList.jsp where I am trying to access the List entries.
testList.jspBut this is getting me this error Please tell me where I am going haywire. TIA
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Giffy Geraldo wrote:Thanks Naik for the quick response. But still I am helpless. here are the jsps that I am trying to test this on

The first JSPHere I am setting the request parameter and then submitting to the testList.jsp where I am trying to access the List entries.
testList.jsp



Hello,

You have used ${params} ...
It should be ${param}

Hope, this solves your problem.

-Deepali
 
Shashank Rudra
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Deepali. That worked. Actually I reposted it with slightly different iteration as other thread
https://coderanch.com/t/450213/JSP/java/using-JSTL-EL-get-set
 
What a show! What atmosphere! What fun! What a 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