Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display a arraylist value in JSP using JSTL

 
Hari Dhanakoti
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a new bie in JSTL me trying to display some values in JSP. Can anyone help me regarding this.
I want to display an arraylist values which are in the form of an value object. How can i display the values in jsp?

I add up list as a parameter parameter to other page say next.jsp

How can i iterate and get the value using JSTL.
 
ujjwal soni
Ranch Hand
Posts: 403
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Make sure that you are using the following code to use the JSTL c tags. The tld will be present inside the standard.jar which you have downloaded from the Jakarta Taglibs project.



To iterate a list that contains just String objects it is well and easy. Say for instance I have an ArrayList object called names which contains the student names.



If you have a similar ArrayList with Student objects filled in, the use the following code



Please note that

Make sure that the standard.jar is in your class path.

If you have any custom objects in your ArrayList then make sure that it has got all the behaviors required. For instance, if you have got Student object inside your ArrayList make sure that the method getName() and getId() is available inside the Student object. The method name is case sensitive and even small errors like getID() instead of getId() will put the developers in the trouble and sometimes take long time to debug.

Try to involve a check before iterating the list to make sure whether the list is empty or not.



Thats it...
 
ujjwal soni
Ranch Hand
Posts: 403
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do remember that ::::::::

In your servlet code set the object of your list as a session or request object...
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do it by using Jsp standard actions & JSTL.

See jsp: usebean, jsp:getAttribute, jsp:setAttribute.
&
c: forEach tag do Google for this You will get lots of result that help you.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSTL tags must be in the proper case: <c:forEach> and so on...
 
Hari Dhanakoti
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Thanks for the valuable reply and got things working here.

Cheers.
 
Pradeep Prabhakaran
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shailesh Narkhede wrote:You can do it by using Jsp standard actions & JSTL.

See jsp: usebean, jsp:getAttribute, jsp:setAttribute.
&
c: forEach tag do Google for this You will get lots of result that help you.




There is no tag such as jsp:getAttribute or jsp:setAttribute.
You can however use getAttribute and setAttribute inside scriptlets,
for e.g<% request.getAttribute ; %>
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Logan Wolverine wrote:
Shailesh Narkhede wrote:You can do it by using Jsp standard actions & JSTL.

See jsp: usebean, jsp:getAttribute, jsp:setAttribute.
&
c: forEach tag do Google for this You will get lots of result that help you.




There is no tag such as jsp:getAttribute or jsp:setAttribute.
You can however use getAttribute and setAttribute inside scriptlets,
for e.g<% request.getAttribute ; %>

Welcome to Javaranch Logan . May be Shailesh meant <jsp:setProperty> & <jsp:getProperty>. Using scriptlets in JSP is not done these days.
 
Pradeep Prabhakaran
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you vijitha,
I mentioned it, so that others who read the topic dont get confused seeing the tag, "jsp:getAttribute"
which doesn exist.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Logan Wolverine wrote:You can however use getAttribute and setAttribute inside scriptlets,

Not in modern JSPs. No Java. No scriptlets.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Logan Wolverine", please check your private messages for an important administrative matter. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic