Announcement Announcement Module
Collapse
No announcement yet.
Help on JSTL question. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help on JSTL question.

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Lucky Number Advisor</title>
    </head>
    <body>
    <%
    int luckyNumber = (new java.util.Random()).nextInt(12) + 1;
    // The value will be in the range between 1 (inclusive) to 12 (inclusive)
    pageContext.setAttribute("luckyN", "" + luckyNumber);
    // set luckyNumber as a page scope variable named luckyN
    %>
    <h2>Don't Forget to consult me before stepping out from your house</h2>
    Hello ! Your Lucky Number today is ${luckyN}.
    <%-- Add in your codes here to complete the page and display the
    expected message --%>

    <c:if test="${luckyN=='1'}">
    your lucky number is 1 which is an odd number

    </c:if>


    </body></html>


    How do i enter the if tag so that if the ramdom number = 1 it will display a message "your lucky number is 1 which is an odd number" and when ramdom number = 12 it will display a message "your lucky number is 12 and is an even number". I think i got the if tag format wrong

  • #2
    make it like this, if i understood your requirement properly then.

    your lucky number is <c:out value="${luckyN}"/>
    which is an <c:choose> <c:when test="${luckyN mod 2 == 0}"> even </c:when> <c:otherwise> odd</c:otherwise> </c:choose> number

    Also this is not right forum for this kind of question/post

    Comment

    Working...
    X