Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can <c:out print an array ?  RSS feed

 
Narue Klo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to do something like this



How can I use <c: out to print an array ?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Narue ,

Did you try to run ? Got any errors ?
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should work for printing an element. Here's a snippet of code from my project.


 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the Difference between ' and "



and typically i use like this


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on Servlets.

For more information, please read this.

This post has been moved to a more appropriate forum.

 
Narue Klo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for wrong section

I have try run


There are no error, but nothing print out
What's wrong ?

please help
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Please give proper name for var attribute . example give var = "narueVariable" and then try the same
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




This is not the correct approach to set y[0][0]. '[]' are bad to use for variable name.

Preferably inside servlets
1) You need to declare a array y[][] of any data type
2) store it in request scope or any other scope
3) use <cut value="${y[0][0]}"/> in JSP.


 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I bet a million bucks you forgot to add the taglib directive



If so, you need to get jstl.jar and standard.jar Here and put them in WEB-INF\lib.

Good luck.
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Beckett wrote:
If so, you need to get jstl.jar and standard.jar Here and put them in WEB-INF\lib.



That would throw error. Check in logs.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Beckett wrote:I bet a million bucks you forgot to add the taglib directive


Dear Ryan, In this Recession , it is difficult to get it back again . it is not only the reasion
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It absolutely doesn't. Try it. What's good Narue? Is that the problem?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan Beckett wrote:It absolutely doesn't. Try it. What's good Narue? Is that the problem?


whether you try this combinations ? i did it .
 
Narue Klo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have included <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>

My problem is , I'm using
in servlet, this servlet controller will return map.put("pArray", pArray);
to jsp page. I need to print out of pArrary
pArray contain data like [][]
how can I print out of pArray using jstl ?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Using map , so wats the issue ?

retreive the map and set it to a variable.
<c:set var="strArr" value="${pArray.arrayNameinmap}"/>

Access it using out like any other EL variable.
<cut value="${strArr[0][0]}" />

 
Narue Klo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is another test


I got error


what did i mistake ?
 
Ryan Beckett
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you are using brackets the structure must be a map, list, or array. The variable or literal inside the brackets is the key or index into he structure.
 
Narue Klo
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for all help
maybe problem is my spring's configurations
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!