If Shawn's response wasn't clear, I'm not sure what else we can say.  The EL parser 
doesn't read scripting variables.  It doesn't know anything about them.  It can't use 
them.  Your first example doesn't work because it's trying to reference a scripting 
variable.  From the EL's point of view, there is no "value" scoped attribute, so the 
result is null.

You should read the specification, if you haven't yet.

> -----Original Message-----
> From: Scott Goldstein [mailto:[EMAIL PROTECTED]]
> 
> I'm not sure that I follow.  How about these two snippets:
> 
> <%
>      String value = "foo";
> %>
> 
> <c:out value="${requestScope[value]}"/>
> 
> and
> 
> <c:out value="${requestScope["foo"]}"/>
> 
> The second one works, while the first doesn't.  The only 
> difference is that 
> the second is using a string literal for the index and the 
> first is using a 
> scripting variable.  Are you saying that scripting variables 
> cannot be used as 
> indexes?
> 
> Basically, prior to this jsp being executed, I've done the following:
> 
> request.setAttribute("foo", "SomeTextToRetrieve");
> 
> So, what I think should happen in the first snippet, is that 
> the variable, 
> value, is resolved to it's String literal, "foo" and then the 
> expression is 
> evaluated just like the second snippet.  This does not appear 
> to be happening.
> 
> Scott
> 
> >===== Original Message From Shawn Bayern 
> <[EMAIL PROTECTED]> =====
> >On Thu, 21 Nov 2002, Scott Goldstein wrote:
> >
> >> I think this may have already been posted, but I don't recall the
> >> answer.
> >>
> >> Aren't the following two snippets identical?
> >>
> >> <%
> >>     String value = "foo";
> >> %>
> >>
> >> <c:out value="${requestScope[value]}"/>
> >>
> >> and
> >>
> >> <%= request.getAttribute(value) %>
> >
> >Nope.  Scripting variables are not automatically made into scoped
> >attributes, and the EL can only refer to scoped attributes.  
> If you added
> >
> >  pageContext.setAttribute("foo", foo);
> >
> >to the upper scriptlet, then the code would be identical.
> >
> >> The first is returning null and the second is returning the
> >> appropriate attribute value.  I looked in the JSTL spec 
> and it looks
> >> like the first should work.
> >>
> >> Is this a bug?
> >
> >No, the behavior is as expected.

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

Reply via email to