my dog learned polymorphism*
The moose likes JSP and the fly likes Can a JSP page retrieve an array off a bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Can a JSP page retrieve an array off a bean? " Watch "Can a JSP page retrieve an array off a bean? " New topic
Author

Can a JSP page retrieve an array off a bean?

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Can a JSP page retrieve an array off a bean? I have two sample lines below. The first line retrieves the bean saved by the servlet, the second line displays the value of property x. Now if x returned a array, how can I display all values of the array? How can I loop through all array values of x? Thanks for the help, I'm confuse on this one.

<jsp:useBean id="key" type="Package.Object" scope="Application" />

<jsp:getProperty name="key" property="x" />
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You'll probably want to look at JSTL for iterating over arrays.


GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Which version of JSP? Please always include this information when posting a new question.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
JSP 2.0
Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Is there a way to do this in a scriptlet?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Of course, but if youare using JSP 2.0 that's like using stone knives and bearskins.

Being sure that the JSTL 1.1 is set up correctly, and that the c library is mapped on the page, it's as easy as (using the naming in your op):

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Is it possible to iterate through a two dimensional array in a bean? All samples I see pertain to single dimensional arrays or just one string values.

I am needing to convert the code below to JSTL. where array_variable is a two dimensional array.

for(int x =0; ${Bean.array_variable[1][x]} != null; x++){
.....
}
[ April 11, 2007: Message edited by: Fritz Largosa ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You can nest <c:forEach ../> tags.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
 
subject: Can a JSP page retrieve an array off a bean?
 
Similar Threads
Pass selected bean property to javascript
how do i pass a bean object from one JSP page to another
accessing indexed bean property
DynaActionForm with ActionMapping
Accessing Property(array object) in a Bean using EL