Skip to main content

JSP Expression Language


I have place couple of examples demonstrating usage of JSTL core tags and EL…
1) JSTL ForEach Tag
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>JSTL: Iterator Support -- Simple Range Iteration Example</title>
</head>
<body bgcolor="#FFFFFF">
<h3>Simple Range Iteration</h3>
<h4>1 to 10</h4>
<c:forEach var="i" begin="1" end="10">
  ${i} &#149;
</c:forEach>
</body>
</html>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>JSTL: Iterator Support -- Iteration Status Example</title>
</head>
<body bgcolor="#FFFFFF">
<h3>Iteration Status</h3>
<h4>Using status information: current, index, count, first, last</h4>
<table border="1">
  <tr>
    <th>index</th>
    <th>count</th>
    <th>last name</th>
    <th>first name</th>
    <th>first?</th>
    <th>last?</th>
  </tr>
  <c:forEach var="customer" items="${customers}" varStatus="status">
    <tr>
      <td><c:out value="${status.index}"/></td>
      <td><c:out value="${status.count}"/></td>
      <td><c:out value="${status.current.lastName}"/></td>
      <td><c:out value="${status.current.firstName}"/></td>
      <td><c:out value="${status.first}"/></td>
      <td><c:out value="${status.last}"/></td>
    </tr>
    <c:if test="${status.last}">
      <c:set var="count" value="${status.count}"/>
    </c:if> 
  </c:forEach>
</table>
<p>There are <c:out value="${count}"/> customers in the list.
<p>
<h4>Iteration using range attributes</h4>
<c:forEach var="i" begin="100" end="200" step="5" varStatus="status">
  <c:if test="${status.first}">
    begin:<c:out value="${status.begin}">begin</c:out> &nbsp; &nbsp;
      end:<c:out value="${status.end}">end</c:out> &nbsp; &nbsp;
     step:<c:out value="${status.step}">step</c:out><br>
    sequence:
  </c:if> 
  <c:out value="${i}"/>
  <c:if test="${status.last}">
    <br>There are <c:out value="${status.count}"/> numbers in the list.
  </c:if> 
</c:forEach>
<p>
</body>
</html>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>JSTL: Iterator Support -- Data Types Example</title>
</head>
<body bgcolor="#FFFFFF">
<h3>Data Types</h3>
<h4>Array of primitives (int)</h4>
<c:forEach var="i" items="${intArray}">
  <c:out value="${i}"/> &#149;
</c:forEach>
<h4>Array of objects (String)</h4>
<c:forEach var="string" items="${stringArray}">
  <c:out value="${string}"/><br>
</c:forEach>
<h4>Enumeration (warning: this only works until enumeration is exhausted!)</h4>
<c:forEach var="item" items="${enumeration}" begin="2" end="10" step="2">
  <c:out value="${item}"/><br>
</c:forEach>
<h4>Properties (Map)</h4>
<c:forEach var="prop" items="${numberMap}" begin="1" end="5">
  <c:out value="${prop.key}"/> = <c:out value="${prop.value}"/><br>
</c:forEach>
<h4>String (Comma Separated Values)</h4>
<c:forEach var="token" items="bleu,blanc,rouge">
  <c:out value="${token}"/><br>
</c:forEach>
</body>
</html>

2) JSTL If Tag
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>JSTL: Conditional Support -- Simple Conditional Execution Example</title>
</head>
<body bgcolor="#FFFFFF">
<h3>Simple Conditional Execution</h3>
<h4>Customers living in the USA</h4>
<c:forEach var="customer" items="${customers}">
  <c:if test="${customer.address.country == 'USA'}">
    ${customer}<br>
Technorati Tags: ,,,
  </c:if>
</c:forEach>
</body>
</html>

3) JSTL Choose Tag
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>JSTL: Conditional Support -- Mutually Exclusive Conditional Execution Example</title>
</head>
<body bgcolor="#FFFFFF">
<h3>Mutually Exclusive Conditional Execution</h3>
<h4>USA:blue Canada:red Others:green</h4>
<c:forEach var="customer" items="${customers}">
  <c:choose>
    <c:when test="${customer.address.country == 'USA'}">
      <font color="blue">
    </c:when>
    <c:when test="${customer.address.country == 'Canada'}">
      <font color="red">
    </c:when>
    <c:otherwise>
      <font color="green">   
    </c:otherwise>     
  </c:choose>
  ${customer}</font><br>
</c:forEach>
</body>
</html>

Technorati Tags: ,,

Comments

Popular posts from this blog

Write a program to calculate the total expenses. Quantity and price per item are input by the user and discount of 10% is offered if the expense is more than 7000.

  #include<iostream.h> #include<conio.h> void main() { int totalexp, qty, price, discount; cout<<" Enter quantity: "; cin>>qty; cout<<" Enter price: "; cin>>price; totalexp=qty*price; if (totalexp>7000) { discount=(totalexp*0.1); totalexp=totalexp-discount; } cout<<" Total Expense is Rs. "<<totalexp; getch(); }

C++ Casino Game Project

Description: This C++ program on CASINO GAME is a simple text base game.We have used procedure oriented method to design this game. This program is without grahics to keep program easy for beginners . Player can deposit his money to play. From this amount he can bet on number between 1 to 12. If he win he gets 10 times of money otherwise lost his money. In this project, We have used programming concept like do..while loop, user defined function, library function like randomize(), random() etc. #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<stdio.h> #include<time.h> void draw_line( int n, char ch); void rules(); void main() { int balanceamt,amt,no,dice; char playername[80],ch; clrscr(); draw_line(60,'='); cout<<" \n\n\n\n\t\tCASINO GAME\n\n\n\n "; draw_line(60,'='); cout<<" \n\n\nEnter Your Name : "; gets(playername); cout<<" \n\n\Enter Deposit amount to play game : ...

How to Create Project report(Vehicle Management System)

INTRODUCTION Vehicle Management System is software which is helpful for bus operators, who wants to operate many bus trips in a day. Vehicle Management System is a windows application written for 32-bit Windows operating systems which focused in the area of adding, editing and deleting the passengers, staff and the bus routes. In this software a person can be register as a user and he can manage the bus routes and the staff, passengers’ details.  He can add a bus and its details including bus route details. User can also add the details of the staff and their duty time in the system. There are mainly 5 modules in this software Bus Management Route Management Employee Management Passenger Management             In Bus module a user can add a new bus details to the database. He can set the details of the route and the timing also. Bus details like the type, engine number, seating capacity and ...