Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Doubt in c:if

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just now i am trying sample programs in JSTL

<%
String name = "vidya";
%>
<c:if test="${name eq 'vidya'}">
${name}
</c:if>

Above program doesnot print anything

But when i change like this, it is working

<%
String name = "vidya";
request.setAttribute("name",name);
%>
<c:if test="${name eq 'vidya'}">
${name}
</c:if>

Why first one is not working???
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${name eq 'vidya'} looks for "name" in a scope.
Your first example does not set the "name" variable in any scope.

The second example sets it in the request scope, so it makes it visible to c:if. You could also set it with c:set
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou for your immediate reply.

I have one small doubt??.Suppose if we are declaring some strings in jsp, it wont fall in any scope...is it so???

Suppose in some scenario we want to use that string in <c:if> then we want to set in some scope and retrieve that..is the only way to do so???
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is.
You'll have to call either
1. pageContext.setAttribute("name", name );
2. or <c:set var="name" value="<%= name %>"/>

But you should try to avoid using scriptlet in your jsp files anyway

[ May 24, 2006: Message edited by: Satou kurinosuke ]
[ May 24, 2006: Message edited by: Satou kurinosuke ]
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Satou...
 
Space pants. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic