• 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

Displaying Values in JSP Page using Struts

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

I am new to struts I am getting problem while displaying the values in JSP page while using HashMap and ArrayList

/*This is the code for Array List*/

ArrayList al = new ArrayList();
while(rs.next()){
al.add(rs.getString(1));
}

I want to display the contents of al object in JSP Page using Stuts <logic:iterate> tag . Thing is this al object is having more that one value
so with out struts we can use for loops and Enumerations to display the value. But pls help me how to display this using struts logic:iterate tag.

Pls give me sample code.

/*This is my hash map code*/

HashMap hm = new HashMap();
while(rs.next()){
hm.put("name",rs.getString(1));
hm.put("age",rs.getString(2));
hm.put("sex",rs.getString(3));
}

The above is my HashMap code i have diplay this value in JSP using logic:iterate tag.


Pls Provide me code for this.

regards
Gopinath
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These links should get you started.
<logic:iterate>
Indexed and Mapped Properties

Sheldon
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One possibility..

First make sure you have the hashmap is in context (use a tag to put it into page context), or just put it in the session if it will be used over several pages..
Let's assume it's in page context, with the name 'contextHash':

<logic:iterate id="dbHash" name="contextHash" type="java.util.HashMap">
Name:<bean:write name="dbhash" property="name" />
Age:<bean:write name="dbhash" property="age" />
.
.
.
</logic:iterate>


Didn't test it.. hopefully it'll help you out.

There's an example of this in the docs.. here
http://struts.apache.org/userGuide/struts-logic.html#iterate
 
reply
    Bookmark Topic Watch Topic
  • New Topic