• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

c:out how to print the values in string

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"/>
<c:out value="${exportMethod[0]}" />

i dont understand where i am lost .
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
%>
<c:out 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

<c:out value="${exportMethod[0]}" />
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good explanation Stefan Evans!
 
What's that smell? I think this tiny ad may have stepped in something.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic