Professional Documents
Culture Documents
Session 11
Session 11
Expression tag is one of the scripting elements in JSP. Expression Tag in JSP is
used for writing your content on the client-side. We can use this tag for displaying
information on the client’s browser. The JSP Expression tag transforms the code
into an expression statement that converts into a value in the form of a string object
and inserts into the implicit output object.
<html>
<body>
<%= GeeksforGeeks %> <!-- Expression tag -->
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-
1">
<title>GeeksforGeeks</title>
</head>
<body>
<% out.println("Hello Geeks "); %> <!-- Sriptlet Tag-->
<% int n1=10; int n2=30; %><!-- Sriptlet Tag-->
<% out.println("<br>sum of n1 and n2 is "); %> <!-- Sriptlet Tag-->
<%= n1+n2 %> <!-- Expression tag -->
</body>
</html>
Implicit Objects in Expression Language (EL)
Implicit Objects Usage
headerValues it maps the request header name to an array of values
Cookie it maps the given cookie name to the cookie value
initParam it maps the initialization parameter
pageContext it provides access to many objects request, session etc.
EL sessionScope example
In this example, we printing the data stored in the session scope using EL. For this
purpose, we have used sessionScope object.
index.jsp
<h3>welcome to index page</h3>
<%
session.setAttribute("user","Aptech");
%>
<a href="process.jsp">visit</a>
process.jsp
Value is ${ sessionScope.user }
EL cookie example
Index1.jsp
1. <h1>First JSP</h1>
2. <%
3. Cookie ck=new Cookie("name","Aptech");
4. response.addCookie(ck);
5. %>
6. <a href="process1.jsp">click</a>
Process1.jsp
Hello, ${cookie.name.value}
Precedence of Operators in EL
There are many operators that have been provided in the Expression Language. Their precedence
are as follows:
[] .
()
* / div % mod
+ - (binary)
== != eq ne
&& and
|| or
?: