• 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 using Struts Tag

 
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Web Frameworks forum...
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

What I would do is create a PersonVO (Value Object) class, which basically contains the variables relating to person - like name, age and sex, as well as getters and setters for each variable.

In your action you populate a collection of PersonVO's (or whatever you want to call it) and set it to the request or session (depending on the lifetime you want for the collection.

Then, in your jsp you add the following code:


colName maps to whatever name you set the collection to on the request, or whereever (there are a number of ways to do it)
type must be a fully qualified (ie package + class name) name of the object within the collection.
property maps to your variable name in your VO


Ok, Well thats how I would do it... Though I wouldn't know what is the *best* way.
Good Luck
K
 
Kim Lilienfeld
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, and generally in my action I would call a Search method in another part of the app which would return me a collection of PersonVO's from the database according to whatever criteria I gave it but if you want to create just a static list for testing purposes it would be something like this:

(in Action)


Oh, and please note my code might not work perfectly cos I'm jsut typing it as I go along and am not working in a Struts environment in my current job but cross fingers it will

K
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic