• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with JSTL usage

 
Davie Lin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • 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 {%>
<cut value="Welcome back"></cut>
<% };%>

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>
<ctherwise>
<cut value="Welcome back"></cut>
</ctherwise>
</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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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}"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for everyone's input
your suggestions work beautifully
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic