Hi David..

There are a few approaches to this, depending on how complicated your
application is.  For small applications, your approach is probably enough.
Having a bean that returns a resultset might be a problem though.  You can
try, in your bean, to return a resultSet but not close it, and then after
the JSP iterates return it back to the bean with another method (like
myBean.returnRS(ResultSet rs) )and close it there.

As far as iterating a resultSet, you'll have to find a JSP Tag lib. that
does this for you (Struts does not have one).  Try Jakarta's TagLibs
(http://jakarta.apache.org/taglibs/index.html).. I'm not sure where else to
look.

The MVC approach would be to have the Controller (a Struts Action) interact
with the bean, and create perhaps a Vector of Vectors representing your
data.  Add it to the request scope, forward to the JSP that displays it, and
use a JSP tag (like Struts' iterate) to go through it.  In MVC, model 2
applications, JSP's would never see ResultSets, the controller does the
dirty work and gets the information nice and pretty for the JSP to display,
and the JSP's job is *only* to display, and do no other work.

I know that this answer is not Struts specific, but I wanted to give as
"implementation-free" an answer I can give, since this is *not* another
struts list.  At least, I hope it's not????

-Roy


----- Original Message -----
From: "David Chu" <[EMAIL PROTECTED]>
Newsgroups: MVC-Programmers,Struts
To: <[EMAIL PROTECTED]>
Sent: Friday, June 21, 2002 9:23 AM
Subject: [MVC-Programmers] Newbie: pass ResultSet to JSP?


> I am trying to get my head around this struts framework for the first
time.
> I am confused about the best/standard way to access data from a JSP.
>
> - Let's say I want a page list_items.jsp.
> - I have access to a bean that has a method that returns the results of a
> database query as a ResultSet object.
> - How should I iterate through the rows of the bean?
> - Complication: my jsp complains that the ResultSet object has been closed
> (because I closed the query)
>
> Is this the prefered encapsulator of data that I should be accessing
through
> my JSP?  Hopefully I can use the <struts-logic:iterate> tag.
>
> Thanks for helping out a new struts developer!
>
> -david
>
> ------------------------------
> David C. Chu
> America Online
> Network Tools Intern
> ------------------------------
>
>
> _______________________________________________
> MVC-Programmers mailing list
> [EMAIL PROTECTED]
> http://www.basebeans.com:8081/mailman/listinfo/mvc-programmers

_______________________________________________
MVC-Programmers mailing list
[EMAIL PROTECTED]
http://www.basebeans.com:8081/mailman/listinfo/mvc-programmers

Reply via email to