| Author |
Help with JSTL usage
|
Davie Lin
Ranch Hand
Joined: Aug 05, 2007
Posts: 294
|
|
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 ut value="Welcome back"></c ut> <% };%> 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 therwise> <c ut value="Welcome back"></c ut> </c therwise> </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
Joined: Dec 11, 2004
Posts: 13410
|
|
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}"
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56218
|
|
<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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56218
|
|
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
Joined: Aug 05, 2007
Posts: 294
|
|
Thanks for everyone's input your suggestions work beautifully
|
 |
 |
|
|
subject: Help with JSTL usage
|
|
|