Thanks, Pierre, I have another question. According to JSTL, the delims is mandatory 
but in Java, when StringToken created, if delimiter is not there, then the default 
delimiter is used. Is it possible for JSTL remove mandatory requirement for delims 
attribute for forToken tag (so it works like in Java)?

Howard

> -----Original Message-----
> From: Pierre Delisle [mailto:[EMAIL PROTECTED]
> Sent: Friday, June 06, 2003 9:30 PM
> To: Tag Libraries Users List
> Subject: Re: forTokens problem
> 
> 
> Howard Lin wrote:
> > I'm trying to use c:forTokens to parse a string, using "\n" 
> as the delimiter and it seems it doesn't work. The jsp code 
> is like this:
> > <c:forTokens items="my_string" delims="\n" var="foo">
> >     <td><c:out value="${foo}"/></td>
> > </c:forTokens>
> > "${foo}" shows the whole entire string instead of the 
> token. but if I use StringTokenizer to parse the string in a 
> script, I got the individual token. So I suspect c:forTokens 
> might be the problem. Thanks,
> 
> Howard Lin wrote:
> > I'm trying to use c:forTokens to parse a string, using "\n" 
> as the delimiter and it seems it doesn't work. The jsp code 
> is like this:
> > <c:forTokens items="my_string" delims="\n" var="foo">
> >     <td><c:out value="${foo}"/></td>
> > </c:forTokens>
> > "${foo}" shows the whole entire string instead of the 
> token. but if I use StringTokenizer to parse the string in a 
> script, I got the individual token. So I suspect c:forTokens 
> might be the problem. Thanks,
> 
> Howard,
> 
> It is not a problem with c:forTokens, but rather the fact that 
> there is no way to pass special Java characters as String literals
> in an attribute value.
> 
> The "\n" is being interpreted as the two characters '\' and
> 'n'.
> 
> One way to get the behavior you want is to make sure the
> "\n" is really passed as a Java String.
> 
> For example:
> 
>    JSTL 1.1 (assuming myString is a scoped variable)
> 
>    <c:forTokens items="${myString}" delims='<%="\n"%>' var="token">
>      <c:out value="${token}"/><br>
>    </c:forTokens>
> 
>    JSTL 1.0 (assuming myString is a scripting variable)
> 
>    <c_rt:forTokens items="<%=myString%>" delims='<%="\n"%>' 
> var="token">
>      <c:out value="${token}"/><br>
>    </c_rt:forTokens>
> 
>    or
>    <% 
>       String lf = "\n"; 
>       pageContext.setAttribute("lf", lf);
>    %>
>    <c:forTokens items="${myString}" delims="${lf}" var="token">
>      <c:out value="${token}"/><br>
>    </c:forTokens>
> 
>     -- Pierre 
> 
> [and yes, maybe the EL should recognize these special character
> sequences... passed the issue to the JSP spec leads]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to