• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with JSTL usage

 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone, thanks for reading my question. I appreciate any opinion offered by anyone.

I am working on a company website and trying to include a chunk of HTML code in a JSP if a user is new to our site. First, I use scriplets like the following

<% if(session.isNew()) {%>
<jsp:include page="greeting.html"></jsp:include>
<% } else {%>
<c:out value="Welcome back"></c:out>
<% };%>

the above scriplet work perfect for my purpose. However, I don't want to use scriplet so I mod the code above using JSTL tags

<c:choose>
<c:when test="session.isNew()">
<jsp:include page="greeting.html"></jsp:include>
</c:when>
<c:otherwise>
<c:out value="Welcome back"></c:out>
</c:otherwise>
</c:choose>

the <c:when> tag is not getting evaluated when I delete the cookie and reopen this JSP. Can anyone suggest where I can change to make it work like the scriplets?

Thank you
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The test attribute in your c:when tag is has a String literal in it.

You'll want to replace that with an EL expression.
test="${pageContext.session.new}"
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<c:when test="session.isNew()">


The test attribute to <c:when> must contain a valid EL expression. You've just given it a text string.

You might try the following:


and then bone up on EL expressions in order to understand the difference.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, Ben and I bonk heads so often!

Also, please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Davie Lin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for everyone's input
your suggestions work beautifully
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic