Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:out how to print the values in string

 
kiran kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have string array
<% String [] mystring = {"one","two","threee" }; %>

and i have defined it a variable using
<c:set var="numbers" value="${mystring}" />

and i want to print(acess) the value in string array
<c ut value="${numbers}" /> and which is not working out.
i dont understand how to access the values if the type string array.

I appreciate your time if some shows me how to access the values in an array.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


where n is the array ordinal.

If you are going to use the EL, I'd suggest you get a copy of the JSP Spec to learn how to write EL expressions.

Also, please be sure to click the disable smilies checkbox when posting code. It will make your <c:out> tags look considerably less surprised
 
kiran kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Bear Bibeault,
thanks for ur reply.
infact i tried that i dont know why it is not working .I am using sun one app server.

here is the code what i have

<% String [] tipReport = {"Transaction Detail","Reference/Batch Summary","Card Type Summary"};
%>

<c:setvar="exportMethod" value="${tipReport}" scope= "request"/>
<cut value="${exportMethod[0]}" />

i dont understand where i am lost .
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"It is not working" is one of the most useless phrases in the english language. What is it doing, and what are you expecting?
 
Stefan Evans
Bartender
Posts: 1722
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL can't access variables created in scriptlet. It can only accses scoped attributes. The easiest way to get a java object into a space that jstl can access is by a setAttribute() call.
<%
String [] tipReport = {"Transaction Detail","Reference/Batch Summary","Card Type Summary"};
pageContext.setAttribute("tipReport", tipReport);
%>
<cut value="${tipReport[0]}" />


The <c:set> tag works well if what you are after is a string, and you nest it between like this: <c:set var="userName"><%= user.getName() %></c:set>
But it won't work in this case.
[ May 02, 2006: Message edited by: Stefan Evans ]
 
kiran kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am expecting it to write the value at the index 0 in the string array exportMethod. what i am doing is also that i beleive.

<cut value="${exportMethod[0]}" />
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, as Stefan pointed out (good catch), your <c:set> will not work as you cannot access scripting variables from the EL.

Why are you creating the array in a scripting variable to begin with? You should be creating a scoped variable in a servlet controller for the page, or at best in a bean.
 
kiran kumar
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans ,

Great and thanks ,what i was trying is to define string array with c:set tag and now i learnt that it not possible.
another thing you told me well is that i have to set the scope.


thanks
 
giridhar challa
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good explanation Stefan Evans!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic