Denys
Denys

Reputation: 4557

jsp content depending on a bool variable value

Is it possible that some content of the .jsp page(say form) is displayed only if a bool variable's value of this jsp page is true?

Thanks for considering my question.

Upvotes: 1

Views: 1230

Answers (3)

Sarin Jacob Sunny
Sarin Jacob Sunny

Reputation: 2138

Use scriptlets for example

<%

if (condition)
{

%>

your code

<%
}

else

{

%>

your code
<%
}
%>

Scriptlets are used for writing java codes.. If you want to get the the value of a variable use

<%=var %>

for example

<% if(id==1)
{
%>

  <tr>
    <td class="BodyStyle"><h5 align="left"><%=TokenNo%></h5></td>
    <td class="BodyStyle"><h5 align="left"><%=Time%></h5></td>
    <td class="BodyStyle"><h5 align="left">Booked</h5></td>
   </td>
   </tr>
  <%
  }
else
{
  %>
   <tr>
    <td class="BodyStyle"><h5 align="left"><%=TokenNo%></h5></td>
    <td class="BodyStyle"><h5 align="left"><%=Time%></h5></td>
    <td class="BodyStyle"><h5 align="left">Available</h5></td>
     </tr>
  <%    
    }
  %>

Upvotes: 0

CloudyMarble
CloudyMarble

Reputation: 37566

Sure

<%
if (your_BoolVar){
%>

Code your form hier

<%
}
%>

Upvotes: 1

socha23
socha23

Reputation: 10239

Use <c:if> from JSTL tag library.

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
...

<c:if test="${myBooleanVariable}">
    <form>
    ...
    </form>
</c:if>

Upvotes: 2

Related Questions