aspose file tools*
The moose likes JSP and the fly likes c:out how to print the values in string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "c:out how to print the values in string " Watch "c:out how to print the values in string " New topic
Author

c:out how to print the values in string

kiran kumar
Greenhorn

Joined: Apr 04, 2006
Posts: 27
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

Joined: Jan 10, 2002
Posts: 61226
    
  66



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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kiran kumar
Greenhorn

Joined: Apr 04, 2006
Posts: 27
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

Joined: Jan 10, 2002
Posts: 61226
    
  66

"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

Joined: Jul 06, 2005
Posts: 1018
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

Joined: Apr 04, 2006
Posts: 27
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

Joined: Jan 10, 2002
Posts: 61226
    
  66

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

Joined: Apr 04, 2006
Posts: 27
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

Joined: May 02, 2006
Posts: 18
good explanation Stefan Evans!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: c:out how to print the values in string