• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display ArrayList in JSP

 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In ActionClass i have an ArrayList which holds the dataObjects.(Data Object has no of fields like Name, Age, Qualification etc).How can i display all these fields in my JSP.

I had set the ArrayList to the form in the ActionClass.


Pls help me.

Thanks in Advance

Vineela
 
Viswa
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
if the array list is a bunch of value from Java Bean. follow,
In action class
....
request.setAttribute("sendToJSP",arrayListObj);
...
In your jsp page
<bean:write name="sendToJSP" property="firstName"/>
<bean:write name="sendToJSP" property="middleName"/>
<bean:write name="sendToJSP" property="lastName"/>
if not bean,
use iterator and find the size using <bean:size/> and iterate continuously.
that's all
Viswa
 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

No, the ArrayList is not a bunch of value from javabean.Rather it is the result of the query which we run.

i.e In ActionClass when i call a method(which runs a query) in DAO, the return type is an ArrayList.

This is the ArrayList which I want to display in JSP

I think now it is clear.

Regards
Vineela
 
Viswa
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In Action class
...
request.setAttribute("sendToJsp",arrayListObj);
...
In JSP page
...
<logic:iterate id="myIter" name="sendToJsp">
<bean:write name="myIter"/>
</logic:iterate>
For example,
Your arrayListObj contains firstname,midname,lastname,mailid.
here in jsp page logic:iterate iterate the loop depends upon the size of the arraylist object.
So this 'll iterate 4 times according to our example.
bean:write gives values from that array list.
Try this.
Regards,
Viswa
 
Pankaj Narang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

U have told the the arraylist contains the dataobjects from the query.So it may conatain many objects .

There r Three ways to disaply them on JSP

1:> Is simple iterate .But if u r using Struts framework it will disobey the laws of MVC. So this should not be done if Struts is used

2:> Use Logic:Iterate and print the values by bean:write but if the records r more it will dispaly all in single page that will be mess .

3:> Use Dispaly Which have the inbuild iterator in them and gives u the choice of no. of pages to be dispalyed per page.For theis taglib u have to give just the name of the list and it will iterate it for u.

Best Regards
Pankaj Narang
 
Kinjal Sonpal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vineela Devi Jakka:
In ActionClass i have an ArrayList which holds the dataObjects.(Data Object has no of fields like Name, Age, Qualification etc).How can i display all these fields in my JSP.
Please try this code and see if it gives what you requireHTH. Please post back for further query.

Thanks and regards,
Kinjal Sonpal
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!