Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying values in JSP using Struts Tag

 
Gopinath Reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Web Frameworks forum...
 
Kim Lilienfeld
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic