aspose file tools*
The moose likes Struts and the fly likes Displaying values in JSP using Struts Tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Displaying values in JSP using Struts Tag" Watch "Displaying values in JSP using Struts Tag" New topic
Author

Displaying values in JSP using Struts Tag

Gopinath Reddy
Greenhorn

Joined: Feb 26, 2004
Posts: 15
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

Joined: Oct 18, 2000
Posts: 4121

Moving this to the Web Frameworks forum...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Kim Lilienfeld
Greenhorn

Joined: Apr 13, 2004
Posts: 25
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

Joined: Apr 13, 2004
Posts: 25
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Displaying values in JSP using Struts Tag