This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Help with JSTL usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Help with JSTL usage" Watch "Help with JSTL usage" New topic
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 {%>
<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

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: 60752
    
  65

<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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help with JSTL usage
 
Similar Threads
jsp: include not working...
Testing equality condition in JSTL
Cannot set parameter in HTML:Link
Nesting JSTL Tags
Best way to find out of user is logged in