File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes display a arraylist value in JSP using JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "display a arraylist value in JSP using JSTL" Watch "display a arraylist value in JSP using JSTL" New topic
Author

display a arraylist value in JSP using JSTL

Hari Dhanakoti
Ranch Hand

Joined: Jan 07, 2008
Posts: 74
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.

Regards,
Hari
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
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...


Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Do remember that ::::::::

In your servlet code set the object of your list as a session or request object...
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
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.


Thanks,
Shailesh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61217
    
  66

The JSTL tags must be in the proper case: <c:forEach> and so on...


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hari Dhanakoti
Ranch Hand

Joined: Jan 07, 2008
Posts: 74
Hi all,

Thanks for the valuable reply and got things working here.

Cheers.
Pradeep Prabhakaran
Greenhorn

Joined: Sep 25, 2010
Posts: 7
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

Joined: Mar 24, 2008
Posts: 3829

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.

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Pradeep Prabhakaran
Greenhorn

Joined: Sep 25, 2010
Posts: 7
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

Joined: Jan 10, 2002
Posts: 61217
    
  66

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

Joined: Jan 10, 2002
Posts: 61217
    
  66

"Logan Wolverine", please check your private messages for an important administrative matter. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display a arraylist value in JSP using JSTL