Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can a JSP page retrieve an array off a bean?

 
Fritz Largosa
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll probably want to look at JSTL for iterating over arrays.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of JSP? Please always include this information when posting a new question.
 
Fritz Largosa
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP 2.0
 
Fritz Largosa
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to do this in a scriptlet?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can nest <c:forEach ../> tags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic