This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Doubt in c:if

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Satou...
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic