Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language JSTL

(JavaServer Pages Standard Tag Library)

Date:03/07/06
Author:Dave Johnston
URL:n/a
Comments:0
Info:http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSTL.html#wp74644
Score: (3.03 in 115 votes)
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 

<c:set var="n" value="99"/>
<html>
<head>
<title><c:out value="${n}"/> Bottles of Beer</title>
</head>
<body>
<c:set var="a" value=" of beer on the wall"/>
<c:set var="c" value=" of beer"/>
<c:set var="d" value="Take one down, pass it around"/>
<c:set var="e" value="."/>
<c:forEach var="i" begin="0" end="${n}" step="1">
  <c:set var="j" value="${n-i}"/>
  <c:choose>
    <c:when test="${j eq 0}">
      <c:set var="b"  scope="session" value="No more bottles"/>
      <c:set var="z"  scope="session" value="${n} bottles"/>
      <c:set var="d" value="Go to the store, buy some more"/>
      <c:set var="e" value="!"/>
    </c:when>
    <c:when test="${j eq 1}">
      <c:set var="b" scope="session" value="${j} bottle"/>
      <c:set var="z"  scope="session" value="No more bottles"/>
    </c:when>
    <c:when test="${j eq 2}">
      <c:set var="b" scope="session" value="${j} bottles"/>
      <c:set var="z"  scope="session" value="${j-1} bottle"/>
    </c:when>
    <c:otherwise>
      <c:set var="b" scope="session" value="${j} bottles"/>
      <c:set var="z"  scope="session" value="${j-1} bottles"/>
    </c:otherwise>
  </c:choose>
  <c:out value="${b}${a}, ${b}${c},"/><br>
  <c:out value="${d}, ${z} ${a}${e}"/><br><br>
</c:forEach>
</body>
</html>

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: