Expression Language (EL) in JSP
Expression Language (EL) in JSP
• <html>
• <body>
• ${1<2}
• ${1+2+3}
• </body>
EXAMPLE
• <% pageContext.setAttribute("pageColor", "blue"); %>
• <body bgcolor="${pageScope.pageColor}">
• <form action="process.jsp">
• Enter Name:<input type="text" name="name" />
• <input type="submit" >
• </form>
To reterive
• Welcome, ${ param.name }
• Example of Expression Language that prints
the value set in the session scope
<a href="process.jsp">visit</a>
To reterieve value
• Value is ${ sessionScope.user }
Reserve words in EL
lt le gt ge
eq ne true false
• <jsp:getProperty name="customer"
property="firstName" />
• ${customer.firstname}
• Deactivating the Expression
• Language in Individual JSP Pages
${(1==2) ? 4 : 5}
• 1
• 2
• 4
• 5
• What gets printed when the following
expression is evaluated? Select the one
correct answer.
${4 div 5}
• 0
• 0.8
• 1
• -1
• What gets printed when the following
expression is evaluated? Select the one
correct answer.
${12 % 4}
• 0
• 3
• 8
• 16
• What is the effect of executing the following JSP statement,
assuming a class with name Employee exists in classes package.
<%@ page import = "classes.Employee" %>
• <jsp:useBean id="employee" class="classes.Employee"
scope="session"/> <jsp:setProperty name="employee"
property="*"/>
${(5*5) ne 25}
• true
• false
• 25
• The expression does not compile as ne is not a
valid operator.
Q What is the effect of evaluation of following expression? Select the one correct
answer.
${'cat' gt 'cap'}
true
• false
• catcap
• The expression does not compile as gt operator cannot be applied on strings.
•
• ++++++++++++++
Q How many numbers are printed, when the following JSTL code fragment is
executed? Select the one correct answer.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach var="item" begin="0" end="10" step="2">
${item}
</c:forEach>
1
• 5
• 6
• 11
• Which of these represent the correct path for
the core JSTL library in JSTL version 1.1? Select
the one correct answer.
http://java.sun.com/jsp/jstl/core
• http://java.sun.com/jsp/core
• http://java.sun.com/core
• http://java.sun.com/jsp/jstl1.1/core
•