SlideShare a Scribd company logo
JEE - JavaServer Pages (JSP)
& Expression Language (EL)
Fahad R. Golra
ECE Paris Ecole d'Ingénieurs - FRANCE
Lecture 4 - JSP & EL
• JSP
• Scripting elements
• Directive elements
• Standard action elements
!
• EL
• Implicit Objects
• Getting Information
2 JEE - JSP & EL
Servlet vs. JSP
3 JEE - JSP & EL
<html>
<body>
<% String name =
request.getParameter(uName); %>
Username: <%= name %>
</body>
</html>
public void doGet(request, response)
{
PrintWriter out = response.getWriter();
String name =
request.getParameter(uName);
out.println( <html><body> );
out.println(”Username: + name);
out.println( </body></html> );
}
Servlets
HTML in Java
JSP
Java in HTML
JSP Architecture
4 JEE - JSP & EL
client Web Server
HTTP Request
HTTP Response
hello.jsp
helloServlet.java
helloServlet.class
read
parse
compile
execute
translationphaserequestprocessing
phase
Implicit Variables in JSP
• request
• This is the HTTPServletRequest object associated with the
request
• response
• This is the HttpServletResponse object associated with the
response to the client
• out
• This is the PrintWriter object used to send output
• session
• This is the HttpSession object associated with request
5 JEE - JSP & EL
Implicit Variables in JSP
• application
• This is the ServletContext object associated with the
application context
!
• config
• This is the ServletConfig object associated with the page
!
• pageContext
• This encapsulates use of server-specific features like higher
performance JspWriters
6 JEE - JSP & EL
Implicit Variables in JSP
• page
• This is a synonym for this. It is used to call the methods
defined by the translated servlet class.
• Exception
• It allows the exception data to be accessed by the designated
JSP
!
• Examples:
• out.print(dataType dt);
• config.getServletName();
• response.setStatus(int statusCode);
• request.getParamter(String name);
7 JEE - JSP & EL
JSP Elements
• There are mainly three types of tag tags (elements) in
JSP, used to put java code in JSP files
• JSP Scripting elements
• JSP Directive elements
• JSP Standard Action elements
8 JEE - JSP & EL
JSP Scripting Elements
• There are four types of JSP Scripting elements
• Declaration tag
• Scripting tag
• Expression tag
• Comment tag
9 JEE - JSP & EL
JSP Declaration tag
• It lets you declare variables and methods in jsp page
• Java code is inside tag
• Variable declaration must end with a semi-colon
!
• Syntax: <%!JavaCode;%>
!
<%! private int i=10;
private int square (int i){
return i*i;
}
%>
10 JEE - JSP & EL
JSP Scripting tag
• It lets you insert java code in the jsp pages
!
• Syntax: <%JavaCode;%>
!
<%
String name = Fabien;
out.println(“Name = “ + name);
%>
11 JEE - JSP & EL
JSP Expression tag
• It is used to insert Java values directly to the output
!
• Syntax: <%=JavaCode%>
!
Current time = <% new java.util.Date()%>
!
12 JEE - JSP & EL
JSP Comment tag
• HTML comments can be seen by the users through
view source
• JSP comments are not visible to the end users
!
• Syntax: <%- - Comment here - -%>
!
<%- - This shows the current date and time- -%>
Current time = <% new java.util.Date()%>
13 JEE - JSP & EL
Scripting Elements Example
<%@ page language="java" contentType="text/html; charset=UTF-8"	
	 pageEncoding="UTF-8"%>	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">	
<html>	
<head>	
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	
<title>Scripting Element Example</title>	
</head>	
<body>	
	 <%--declaration tag --%>	
	 <%!int i = 10;%>	
!
	 <%--scriptlet tag --%>	
	 <%	
	 	 out.print("i = " + i);	
	 %>	
	 <BR />	
	 <BR />	
	 <%	
	 	 out.print("Loop execution:");	
	 %>	
	 <BR />
14
Scripting Elements Example
<%	
	 	 while (i < 20) {	
	 	 	 out.print("value of i = " + i);	
	 	 	 i++;	
	 %>	
	 <BR />	
	 <%	
	 	 }	
	 %>	
	 <BR />	
	 <%-- expression tag --%>	
	 <%!int a = 5, b = 15;%>	
	 The addition of a + b = 5 + 15 =	
	 <%=a + b%>	
	 <BR /> Current time:	
	 <%=new java.util.Date()%>	
</body>	
</html>
15
Scripting Elements Example
16 JEE - JSP & EL
JSP Directive Elements
• They give special information about the page to JSP
Engine
• They are handled only once at translation phase
!
• Syntax: <%@ directive-name [attribute=“value”
attribute = “value” … ]%>
!
• Types of directives
• page directive
• include directive
• taglib directive
17 JEE - JSP & EL
Page directive
• It is used to specify attributes for the JSP page
• e.g. making session data unavailable to a page
!
!
• Syntax:
<%@ page [attribute=“value” attribute = “value” … ] %>
!
• Example:
<%@ page language=“java” session=“true” … %>
18 JEE - JSP & EL
Page directive - attributes
19
Attribute Description Syntax Example
language The language to be
used in JSP file
language=“java” <%@page
language=“java” %>
import List of packages
need by servlet
import=“package.c
lass,
package.class”
<%@page
import=“java.util.*,
java.io.*” %>
extends superclass of
servlet
extends =
“package.class”
<%@page
extends=“com.ece.Lo
gin” %>
session true binds to
existing session or
creates new. false
means no session
session = “true |
false”
<%@page
session=“true” %>
Page directive - attributes
20
Attribute Description Syntax Example
buffer defines the buffer
size for out.
default is 8kb
buffer=“size(kb) |
none”
<%@page
buffer=“16kb” %>
isThreadS
afe
choice between
multithreading and
single ThreadModel
isThreadSafe=“tru
e | false”
<%@page
isThreadSafe=“true”
%>
autoFlush true means flush
buffer when full,
false means to
throw exception
autoFlush=“true |
false”
<%@page
autoFlush=“true” %>
pageEnco
ding
datatype of page
encoding
pageEncoding=“en
ocding”
<%@page
pageEncoding =
“ISO-8859-1” %>
Page directive - attributes
21
Attribute Description Syntax Example
info string for
getServletInfo
info=“information
message”
<%@page
buffer=“16kb” %>
contentType MIME type of
output
contentType=“MIM
E-Type”
<%@page contentType
=“text/html; charset =
UTF-8” %>
isELignored expression
language available?
isELIgnored=“true
| false”
<%@page isELignored
=“true” %>
isErrorPage Can current page
act as error page ?
isErrorPage=“true
| false”
<%@page isErrorPage =
“false” %>
errorPage define error page
URL for unchecked
runtime exception
errorPage = “URL” <%@page errorPage =
“error.jsp” %>
Include directive
• It is used to insert code (static resource only) of a file
inside jsp file at a specified place in the translation
phase
• Headers, footers, tables and navigation menus that
are common to multiple pages can be placed using it.
!
• Syntax:
<%@ include file=“/folder_name/file_name”%>
!
• Example:
<%@ include file=“footer.html”%>
22 JEE - JSP & EL
Taglib directive
• It make custom actions available in the jsp file, using
the tag libraries
!
• Syntax:
<%tablib uri=“tag Library_path” prefix=“tag_prefix”%>
• uri = Absolute path of a tag library descriptor
• prefix= Prefix to identify custom tags from a specific
library
!
• Example:
<%@ taglib uri=/tlds/ColouredTable.tld” prefix=“ct”@>
23 JEE - JSP & EL
JSP to Servlet translation
24 JEE - JSP & EL
<%@ page import= abc.* %>
<html>
<body>
<% int i = 10; %>
<%! int count = 0; %>
Hello! Welcome
<%! Public void hello()
{
out.println( Hello );
} %>
</body>
</html>
import javax.servlet.HttpServlet.*
import abc.*;
public class Hello_jsp extends HttpServlet
{
int count = 0;
public void hello()
{
out.println( Hello );
}
public void _jspService(req, res)
{
int i = 10;
out.println( <html>r<body> );
out.println( Hello! Welcome );
}
}
JSP Standard Action Elements
• They are used to create, modify or use other objects
!
• Only coded in strict XML syntax
!
• General usage
• inserting a file
• reuse JavaBeans component
• forward to another page
• generate HTML for a Java Plugin, etc.
25 JEE - JSP & EL
Types of standard action types
1. <jsp:param>
2. <jsp:include>
3. <jsp:forward>
4. <jsp:fallback>
5. <jsp:plugin>
6. <jsp:useBean>
7. <jsp:setProperty>
8. <jsp:getProperty>
26 JEE - JSP & EL
Standard action - <jsp:param>
• It provides other tags with additional information as
name value pairs
• Used along with jsp:include, jsp:forward, jsp:plugin
!
• Syntax:
<jsp:param name=“parameter_name”
value=“parameter_value” />
!
<jsp:param name=“parameter_name”
value=“paramter_value> </jsp:param>
27 JEE - JSP & EL
Standard action - <jsp:param>
• Example:
!
<jsp:param name=“font_color” value=“red” />
!
<jsp:param name=“font_color” value=“red”>
<jsp:param>
28 JEE - JSP & EL
Standard action - <jsp:include>
• This allows to include a static or dynamic resource in
the JSP at request time.
• If page is buffered then the buffer is flushed prior to
the inclusion
• Syntax:
<jsp:include page=“file_name” flush=“true|false”/>
!
<jsp:include page=“file_name” flush=“true|false”>
<jsp:param name=“parameter_name”
value=“parameter_value”/>
</jsp:include>
29 JEE - JSP & EL
Example - <jsp:include>
Student.jsp
!
<%@ page language="java" contentType="text/html; charset=UTF-8"	
	 pageEncoding="UTF-8"%>	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">	
<html>	
<head>	
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	
<title>Student</title>	
</head>	
<body>	
	 <b><i>Student details:</i></b>	
	 <br>	
	 <%	
	 	 out.print(request.getParameter("name1") + " is taking the course of "	
	 	 	 	 + request.getParameter("course1"));	
	 %>	
	 <br>	
	 <%	
	 	 out.print(request.getParameter("name2") + " is taking the course of "	
	 	 	 	 + request.getParameter("course2"));	
	 %>	
</body>	
</html>
30
Example - <jsp:include>
StudentInfo.jsp!
<%@ page language="java" contentType="text/html; charset=UTF-8"	
	 pageEncoding="UTF-8"%>	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/
TR/html4/loose.dtd">	
<html>	
<head>	
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	
<title>Student Information</title>	
</head>	
<body>	
	 <jsp:include page="Student.jsp">	
	 	 <jsp:param value="Fabien" name="name1" />	
	 	 <jsp:param value="JEE" name="course1" />	
	 	 <jsp:param value="Antoine" name="name2" />	
	 	 <jsp:param value="Java" name="course2" />	
	 </jsp:include>	
</body>	
</html>
31
Directive include vs Action include
32 JEE - JSP & EL
Include Syntax Inclusion
time
Content
type
Parsing
Directive <%@include
file=“file_na
me”%>
Translation
phase
Static Container
Action <jsp:include
page=file_na
me”%>
Request
processing
phase
Static or
dynamic
Not parsed,
included in
the container
Standard action - <jsp:forward>
• This is used to forward the request to another page
!
• Syntax:
<jsp:forward page=“file_name”/>
!
<jsp:forward page=“file_name”>
<jsp:param name=“parameter_name
value=“paramater_value”/>
</jsp:forward>
33 JEE - JSP & EL
Standard action - <jsp:fallback>
• Used in conjunction with <jsp:plugin>
• This element can be used to specify an error string to
be sent to the user in case the plugin fails
!
• Syntax:
<jsp:fallback> text message for user </jsp:fallback>
34 JEE - JSP & EL
Standard action - <jsp:plugin>
• Generates browser-specific code that makes an
Object or Embed tag for the Java plugin
• Can be used for applets and JavaBeans
• Syntax:
<jsp:plugin type=“bean|apple”
code =“className.class”
codebase=“path of className.class in WebRoot”
[name= “name of bean or applet]
[align=“bottom|top|middle|left|right]
[height:”diplayPixels”] ….. >
35 JEE - JSP & EL
Standard action - <jsp:plugin>
[<jsp:params>
<jsp:param name=“parameter_name”
value=“parameter_value”/>
<jsp:param name=“parameter_name”
value=“parameter_value”/>
…….
</jsp:params>]
[<jsp:fallback> text message </jsp:fallback>]
</jsp:plugin>
36 JEE - JSP & EL
Standard action - <jsp:useBean>
• It is used to find and instantiate a JavaBean
• A common way of interaction between web pages
• Scopes:
• page: (default) within a JSP page
• request: within the same request
• session: all JSPs in the same session
• application: within the same context
37 JEE - JSP & EL
Standard action - <jsp:useBean>
• Syntax:
<jsp:useBean id= "bean_id"
scope= "page | request | session | application"
class= “packageName.className"
beanName="packageName.className" >
</jsp:useBean>
38 JEE - JSP & EL
Standard action - <jsp:setProperty>
• It is used to set the value of a bean’s property
!
• Syntax:
!
<jsp:setProperty name="bean_id" property= "*"
| property="propertyName" param="parameterName"
| property="propertyName" value="propertyValue" />
39 JEE - JSP & EL
Standard action - <jsp:getProperty>
• It is used to retrieve the value of a bean’s property,
convert it into a string and insert it into the output.
!
• Syntax:
<jsp:getProperty name=“bean_id”
property=“propertyName”/>
40 JEE - JSP & EL
JSP-JavaBeans Example
package com.ece.jee;	
!
public class BackgroundColor {	
	 int red, blue, green;	
!
public BackgroundColor() {	
	 	 super();	
	 	 this.red = 0;	
	 	 this.blue = 0;	
	 	 this.green = 255;	
	 }	
!
public int getRed() {	
	 	 return red;	
	 }	
!
public void setRed(int red) {	
	 	 this.red = red;	
	 }
41
JSP-JavaBeans Example
public int getBlue() {	
	 	 return blue;	
	 }	
!
public void setBlue(int blue) {	
	 	 this.blue = blue;	
	 }	
!
public int getGreen() {	
	 	 return green;	
	 }	
!
public void setGreen(int green) {	
	 	 this.green = green;	
	 }	
}	
42
JSP-JavaBeans Example
<%@ page language="java" contentType="text/html; charset=UTF-8"	
	 pageEncoding="UTF-8"%>	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">	
<jsp:useBean id="bgc" class="com.ece.jee.BackgroundColor"	
	 scope="session" />	
<html>	
<head>	
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">	
<title>Insert title here</title>	
</head>	
!
<jsp:setProperty name="bgc" property="red" param="red" />	
<jsp:setProperty name="bgc" property="green" param="green" />	
<jsp:setProperty name="bgc" property="blue" param="blue" />
43
JSP-JavaBeans Example
<body	
	 style="background: rgb(<jsp:getProperty name="bgc" property="red"/>, 	
	 <jsp:getProperty name="bgc" property="green"/>, 	
	 <jsp:getProperty name="bgc" property="blue"/>)">	
	 	
	 <h3>Colorful Hello !!!</h3>	
!
	 <form name="colorForm" action="ColorExample.jsp" method="post">	
	 	 Red: <input type="text" name="red"> Green: <input type="text"	
	 	 	 name="green"> Blue: <input type="text" name="blue"> <input	
	 	 	 type="submit">	
	 </form>	
!
</body>	
</html>
44
Initialization parameters
In Deployment Descriptor:
<servlet>	
<servlet-name>InitJSP</servlet-name>	
<jsp-file>/Example.jsp</jsp-file>	
<init-param>	
<param-name>userName</param-name>	
<param-value>Abcd</param-value>	
</init-param>	
</servlet>	
	
<servlet-mapping>	
<servlet-name>InitJSP</servlet-name>	
<url-pattern>/Example.jsp</url-pattern>	
</servlet-mapping>	
!
In JSP:
Our initialization parameter has username value = 	
	 <%= getServletConfig().getInitParameter("userName") %>
45 JEE - JSP & EL
Overriding Init()
<%! 	
public void jspInit(){	
	 String configUser =
getServletConfig().getInitParameter("userName");	
	 getServletContext().setAttribute("contextUser", configUser);	 	
}	
%>	
!
Our initialization parameter has username value = 	
	 <%= config.getInitParameter("userName") %>	
<br/>	
Servlet context value for user = 	
	 <%= application.getAttribute("contextUser") %>
46
JSP Documents
47 JEE - JSP & EL
Expression Language (EL)
• Incorporated in JSP2.0
• Accessing bean using simple syntax
• ${name} for a simple variable
• ${name.foo.bar} for a nested property
!
• Kinds of expressions
• Arithmetic
<jsp:setProperty name="box" property=“perimeter"
value=“${2*box.width+2*box.height}"/>
!
• Logical
<c:if test="${bean1.a < 3}" > ... </c:if>
48 JEE - JSP & EL
Operators in EL
49 JEE - JSP & EL
Operator Description
. Access a bean property or Map entry
[] Access an array or List element
( ) Group a subexpression to change the
evaluation order
+ Addition
- Subtraction or negation of a value
* Multiplication
/ or div Division
% or mod Modulo (remainder)
Operators in EL
50 JEE - JSP & EL
Operator Description
== or eq Test for equality
!= or ne Test for inequality
< or lt Test for less than
> or gt Test for greater than
<= or le Test for less than or equal
>= or gt Test for greater than or equal
&& or and Test for logical AND
|| or or Test for logical OR
! or not Unary Boolean complement
empty Test for null, empty String, array or
Collection.
func(args) A function call
Implicit Objects in EL
51
Implicit object Description
pageScope Scoped variables from page scope
requestScope Scoped variables from request scope
sessionScope Scoped variables from session scope
applicationScope Scoped variables from application scope
param Request parameters as strings
paramValues Request parameters as collections of strings
header HTTP request headers as strings
headerValues HTTP request headers as collections of strings
initParam Context-initialization parameters
cookie Cookie values
pageContext The JSP PageContext object for the current page
Implicit Objects in EL
• Not the same as implicit objects of JSP
• except pageContext
!
• pageContext is used to access other JSP implicit
objects
!
• Syntax:
${pageContext.request.queryString}
52 JEE - JSP & EL
Scope Objects
• These scope objects allow access to variables stored
at different access levels
• requestScope
• sessionScope
• applicationScope
• pageScope
!
• Example
Servlet context value for user = 	
	 <%= application.getAttribute("contextUser") %>	
• Using EL
Servlet context value for user = ${applicationScope.contextUser}
53 JEE - JSP & EL
Handling Attributes
• EL is used to read values, not to set values, JSP
serves as “view” in MVC
!
• In Servlet
request.setAttribute(“contextUser”,cu);
!
• Using EL
${requestScope[“contextUser”].name}
${sessionScope[“contextUser”].name}
${applicationScope[“contextUser”].name}
54 JEE - JSP & EL
Param & ParamValues
• Gives you access to parameter values using
request.getParameter and
request.getParameterValues methods
!
• Example: for a parameter named password
${param.password}
${param[“password”]}
55 JEE - JSP & EL
Getting Header Information
• In JSP
<%= request.getHeader(“host”)%>
!
• With EL
${header.host}
${header[“host”]}
56 JEE - JSP & EL
Init Parameter
• Deployment Descriptor
<context-param>	

<param-name>name</param-name>	

<param-value>Antoine</param-value>
</context-param>
!
• With expression

<%= application.getInitParameter(“name”) %>
!
• With EL
${initParam.name}
57 JEE - JSP & EL
Accessing properties
• If the expression has a variable followed by a dot, then
this variable must be a bean or a map
!
• Example:
${person.name}
58 JEE - JSP & EL
“name”,”Fabien”
name
!
getName()
setName()
java.util.Map a bean
Accessing properties
• If the expression has a variable followed by a bracket,
then this variable must be a bean, a map, a List or an
Array
!
• Example:
${person[name]}
59 JEE - JSP & EL
“name”,”Fabien”
name
!
getName()
setName()
java.util.Map a bean
1. Fabien
2. Antoine
3. Serge
1.Fabien 2.Antoine 3.Serge
an Array
a List
Array
<%!	
String[] nameList = {"Alpha","Bravo","Charlie"}; 	
%>	
!
<% request.setAttribute("name", nameList);%>	
	 	
Name : ${name} 	
<BR />	
Name : ${name[0]} 	
<BR />	
Name : ${name["0"]}
60 JEE - JSP & EL
HashMap
<%!	
Map<String,String> studentMap = new HashMap<String,String>(); 	
%>	
!
<%	
studentMap.put("name","Fabien");	
request.setAttribute("studentMap", studentMap);	
%>	
!
Name : ${studentMap.name} 	
<BR />	
Name : ${studentMap[name]} 	
<BR />	
Name : ${studentMap["name"]}
61 JEE - JSP & EL
Requesting Parameters
• In HTML
<form action=“UserBean.jsp”>

First Name : <input type=“text” name=“firstName”>
Last Name: <input type=“text” name=“lastName”>
<input type=“submit”>	

</form>	

!
• In JSP	

${param.firstName}
${param.lastName}
62 JEE - JSP & EL
63 JEE - JSP & EL

More Related Content

PDF
Lecture 2: Servlets
PDF
Lecture 5 JSTL, custom tags, maven
PDF
Lecture 6 Web Sockets
PDF
Lecture 3: Servlets - Session Management
PDF
Lecture 9 - Java Persistence, JPA 2
PDF
Expression Language in JSP
PPTX
JSP - Java Server Page
PDF
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 2: Servlets
Lecture 5 JSTL, custom tags, maven
Lecture 6 Web Sockets
Lecture 3: Servlets - Session Management
Lecture 9 - Java Persistence, JPA 2
Expression Language in JSP
JSP - Java Server Page
Lecture 7 Web Services JAX-WS & JAX-RS

What's hot (19)

PPT
Java Server Faces (JSF) - Basics
PDF
JAVA EE DEVELOPMENT (JSP and Servlets)
PPT
Jsp sasidhar
ODP
Spring 4 final xtr_presentation
PDF
Lecture 1: Introduction to JEE
PPT
Java Server Pages
PPSX
Java server pages
PPT
J2EE - JSP-Servlet- Container - Components
PPTX
Java Server Pages
PPT
Spring MVC
PPTX
JSP- JAVA SERVER PAGES
PPTX
Java Servlet
PPS
Jsp element
PPT
JAVA Servlets
PDF
Spring 4 Web App
PPTX
java Servlet technology
DOC
Java Servlets & JSP
PPTX
PPTX
Database connect
Java Server Faces (JSF) - Basics
JAVA EE DEVELOPMENT (JSP and Servlets)
Jsp sasidhar
Spring 4 final xtr_presentation
Lecture 1: Introduction to JEE
Java Server Pages
Java server pages
J2EE - JSP-Servlet- Container - Components
Java Server Pages
Spring MVC
JSP- JAVA SERVER PAGES
Java Servlet
Jsp element
JAVA Servlets
Spring 4 Web App
java Servlet technology
Java Servlets & JSP
Database connect
Ad

Viewers also liked (20)

PDF
Lecture 10 - Java Server Faces (JSF)
PDF
Lecture 8 Enterprise Java Beans (EJB)
PDF
Enterprise Java Beans - EJB
PDF
Tutorial 4 - Basics of Digital Photography
PPT
Ejb in java. part 1.
PDF
TNAPS 3 Installation
PPT
Hibernate
PPTX
Hibernate Training Session1
PPTX
Introduction to AJAX and DWR
PPTX
JSON-(JavaScript Object Notation)
PDF
2012-12-01 03 Битва ORM: Hibernate vs MyBatis. Давайте жить дружно!
PDF
Jsf Framework
PDF
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
PPTX
Spring boot for buidling microservices
PDF
Apache Lucene + Hibernate = Hibernate Search
PPS
JSP Error handling
PPT
Unified Expression Language
PPT
JMS Introduction
PPT
Java Server Faces (JSF) - advanced
PDF
The Modern Java Web Developer Bootcamp - Devoxx 2013
Lecture 10 - Java Server Faces (JSF)
Lecture 8 Enterprise Java Beans (EJB)
Enterprise Java Beans - EJB
Tutorial 4 - Basics of Digital Photography
Ejb in java. part 1.
TNAPS 3 Installation
Hibernate
Hibernate Training Session1
Introduction to AJAX and DWR
JSON-(JavaScript Object Notation)
2012-12-01 03 Битва ORM: Hibernate vs MyBatis. Давайте жить дружно!
Jsf Framework
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Spring boot for buidling microservices
Apache Lucene + Hibernate = Hibernate Search
JSP Error handling
Unified Expression Language
JMS Introduction
Java Server Faces (JSF) - advanced
The Modern Java Web Developer Bootcamp - Devoxx 2013
Ad

Similar to Lecture 4: JavaServer Pages (JSP) & Expression Language (EL) (20)

PPTX
JSP AND XML USING JAVA WITH GET AND POST METHODS
PPTX
SCWCD : Java server pages CHAP : 9
PPTX
JSP Directives
PPTX
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
PPTX
Introduction - Java Server Programming (JSP)
PDF
Java Web Programming [4/9] : JSP Basic
PDF
Lap trinh web [Slide jsp]
PPTX
Jsp elements
PPT
Java serverpages
PPTX
Introduction to JSP
PPTX
Java Server Pages
PPT
Jsp intro
PDF
PPTX
JSP.pptx
PPT
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
PPT
JSP Processing
PPTX
WT Unit-Vuufvmjn dissimilating Dunkirk k
PPTX
Session 36 - JSP - Part 1
PPTX
Module 3.pptx.............................
PPTX
JAVA SERVER PAGES
JSP AND XML USING JAVA WITH GET AND POST METHODS
SCWCD : Java server pages CHAP : 9
JSP Directives
Internet and Web Technology (CLASS-14) [JSP] | NIC/NIELIT Web Technology
Introduction - Java Server Programming (JSP)
Java Web Programming [4/9] : JSP Basic
Lap trinh web [Slide jsp]
Jsp elements
Java serverpages
Introduction to JSP
Java Server Pages
Jsp intro
JSP.pptx
Session 5 : intro to jsp - Giáo trình Bách Khoa Aptech
JSP Processing
WT Unit-Vuufvmjn dissimilating Dunkirk k
Session 36 - JSP - Part 1
Module 3.pptx.............................
JAVA SERVER PAGES

More from Fahad Golra (9)

PDF
Seance 4- Programmation en langage C
PDF
Seance 3- Programmation en langage C
PDF
Seance 2 - Programmation en langage C
PDF
Seance 1 - Programmation en langage C
PDF
Tutorial 3 - Basics of Digital Photography
PDF
Tutorial 2 - Basics of Digital Photography
PDF
Tutorial 1 - Basics of Digital Photography
PPTX
Deviation Detection in Process Enactment
PPTX
Meta l metacase tools & possibilities
Seance 4- Programmation en langage C
Seance 3- Programmation en langage C
Seance 2 - Programmation en langage C
Seance 1 - Programmation en langage C
Tutorial 3 - Basics of Digital Photography
Tutorial 2 - Basics of Digital Photography
Tutorial 1 - Basics of Digital Photography
Deviation Detection in Process Enactment
Meta l metacase tools & possibilities

Recently uploaded (20)

PDF
TR - Agricultural Crops Production NC III.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Institutional Correction lecture only . . .
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
TR - Agricultural Crops Production NC III.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
O7-L3 Supply Chain Operations - ICLT Program
Week 4 Term 3 Study Techniques revisited.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O5-L3 Freight Transport Ops (International) V1.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Institutional Correction lecture only . . .
Microbial disease of the cardiovascular and lymphatic systems
Anesthesia in Laparoscopic Surgery in India
Final Presentation General Medicine 03-08-2024.pptx
Pre independence Education in Inndia.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
102 student loan defaulters named and shamed – Is someone you know on the list?

Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)

  • 1. JEE - JavaServer Pages (JSP) & Expression Language (EL) Fahad R. Golra ECE Paris Ecole d'Ingénieurs - FRANCE
  • 2. Lecture 4 - JSP & EL • JSP • Scripting elements • Directive elements • Standard action elements ! • EL • Implicit Objects • Getting Information 2 JEE - JSP & EL
  • 3. Servlet vs. JSP 3 JEE - JSP & EL <html> <body> <% String name = request.getParameter(uName); %> Username: <%= name %> </body> </html> public void doGet(request, response) { PrintWriter out = response.getWriter(); String name = request.getParameter(uName); out.println( <html><body> ); out.println(”Username: + name); out.println( </body></html> ); } Servlets HTML in Java JSP Java in HTML
  • 4. JSP Architecture 4 JEE - JSP & EL client Web Server HTTP Request HTTP Response hello.jsp helloServlet.java helloServlet.class read parse compile execute translationphaserequestprocessing phase
  • 5. Implicit Variables in JSP • request • This is the HTTPServletRequest object associated with the request • response • This is the HttpServletResponse object associated with the response to the client • out • This is the PrintWriter object used to send output • session • This is the HttpSession object associated with request 5 JEE - JSP & EL
  • 6. Implicit Variables in JSP • application • This is the ServletContext object associated with the application context ! • config • This is the ServletConfig object associated with the page ! • pageContext • This encapsulates use of server-specific features like higher performance JspWriters 6 JEE - JSP & EL
  • 7. Implicit Variables in JSP • page • This is a synonym for this. It is used to call the methods defined by the translated servlet class. • Exception • It allows the exception data to be accessed by the designated JSP ! • Examples: • out.print(dataType dt); • config.getServletName(); • response.setStatus(int statusCode); • request.getParamter(String name); 7 JEE - JSP & EL
  • 8. JSP Elements • There are mainly three types of tag tags (elements) in JSP, used to put java code in JSP files • JSP Scripting elements • JSP Directive elements • JSP Standard Action elements 8 JEE - JSP & EL
  • 9. JSP Scripting Elements • There are four types of JSP Scripting elements • Declaration tag • Scripting tag • Expression tag • Comment tag 9 JEE - JSP & EL
  • 10. JSP Declaration tag • It lets you declare variables and methods in jsp page • Java code is inside tag • Variable declaration must end with a semi-colon ! • Syntax: <%!JavaCode;%> ! <%! private int i=10; private int square (int i){ return i*i; } %> 10 JEE - JSP & EL
  • 11. JSP Scripting tag • It lets you insert java code in the jsp pages ! • Syntax: <%JavaCode;%> ! <% String name = Fabien; out.println(“Name = “ + name); %> 11 JEE - JSP & EL
  • 12. JSP Expression tag • It is used to insert Java values directly to the output ! • Syntax: <%=JavaCode%> ! Current time = <% new java.util.Date()%> ! 12 JEE - JSP & EL
  • 13. JSP Comment tag • HTML comments can be seen by the users through view source • JSP comments are not visible to the end users ! • Syntax: <%- - Comment here - -%> ! <%- - This shows the current date and time- -%> Current time = <% new java.util.Date()%> 13 JEE - JSP & EL
  • 14. Scripting Elements Example <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Scripting Element Example</title> </head> <body> <%--declaration tag --%> <%!int i = 10;%> ! <%--scriptlet tag --%> <% out.print("i = " + i); %> <BR /> <BR /> <% out.print("Loop execution:"); %> <BR /> 14
  • 15. Scripting Elements Example <% while (i < 20) { out.print("value of i = " + i); i++; %> <BR /> <% } %> <BR /> <%-- expression tag --%> <%!int a = 5, b = 15;%> The addition of a + b = 5 + 15 = <%=a + b%> <BR /> Current time: <%=new java.util.Date()%> </body> </html> 15
  • 17. JSP Directive Elements • They give special information about the page to JSP Engine • They are handled only once at translation phase ! • Syntax: <%@ directive-name [attribute=“value” attribute = “value” … ]%> ! • Types of directives • page directive • include directive • taglib directive 17 JEE - JSP & EL
  • 18. Page directive • It is used to specify attributes for the JSP page • e.g. making session data unavailable to a page ! ! • Syntax: <%@ page [attribute=“value” attribute = “value” … ] %> ! • Example: <%@ page language=“java” session=“true” … %> 18 JEE - JSP & EL
  • 19. Page directive - attributes 19 Attribute Description Syntax Example language The language to be used in JSP file language=“java” <%@page language=“java” %> import List of packages need by servlet import=“package.c lass, package.class” <%@page import=“java.util.*, java.io.*” %> extends superclass of servlet extends = “package.class” <%@page extends=“com.ece.Lo gin” %> session true binds to existing session or creates new. false means no session session = “true | false” <%@page session=“true” %>
  • 20. Page directive - attributes 20 Attribute Description Syntax Example buffer defines the buffer size for out. default is 8kb buffer=“size(kb) | none” <%@page buffer=“16kb” %> isThreadS afe choice between multithreading and single ThreadModel isThreadSafe=“tru e | false” <%@page isThreadSafe=“true” %> autoFlush true means flush buffer when full, false means to throw exception autoFlush=“true | false” <%@page autoFlush=“true” %> pageEnco ding datatype of page encoding pageEncoding=“en ocding” <%@page pageEncoding = “ISO-8859-1” %>
  • 21. Page directive - attributes 21 Attribute Description Syntax Example info string for getServletInfo info=“information message” <%@page buffer=“16kb” %> contentType MIME type of output contentType=“MIM E-Type” <%@page contentType =“text/html; charset = UTF-8” %> isELignored expression language available? isELIgnored=“true | false” <%@page isELignored =“true” %> isErrorPage Can current page act as error page ? isErrorPage=“true | false” <%@page isErrorPage = “false” %> errorPage define error page URL for unchecked runtime exception errorPage = “URL” <%@page errorPage = “error.jsp” %>
  • 22. Include directive • It is used to insert code (static resource only) of a file inside jsp file at a specified place in the translation phase • Headers, footers, tables and navigation menus that are common to multiple pages can be placed using it. ! • Syntax: <%@ include file=“/folder_name/file_name”%> ! • Example: <%@ include file=“footer.html”%> 22 JEE - JSP & EL
  • 23. Taglib directive • It make custom actions available in the jsp file, using the tag libraries ! • Syntax: <%tablib uri=“tag Library_path” prefix=“tag_prefix”%> • uri = Absolute path of a tag library descriptor • prefix= Prefix to identify custom tags from a specific library ! • Example: <%@ taglib uri=/tlds/ColouredTable.tld” prefix=“ct”@> 23 JEE - JSP & EL
  • 24. JSP to Servlet translation 24 JEE - JSP & EL <%@ page import= abc.* %> <html> <body> <% int i = 10; %> <%! int count = 0; %> Hello! Welcome <%! Public void hello() { out.println( Hello ); } %> </body> </html> import javax.servlet.HttpServlet.* import abc.*; public class Hello_jsp extends HttpServlet { int count = 0; public void hello() { out.println( Hello ); } public void _jspService(req, res) { int i = 10; out.println( <html>r<body> ); out.println( Hello! Welcome ); } }
  • 25. JSP Standard Action Elements • They are used to create, modify or use other objects ! • Only coded in strict XML syntax ! • General usage • inserting a file • reuse JavaBeans component • forward to another page • generate HTML for a Java Plugin, etc. 25 JEE - JSP & EL
  • 26. Types of standard action types 1. <jsp:param> 2. <jsp:include> 3. <jsp:forward> 4. <jsp:fallback> 5. <jsp:plugin> 6. <jsp:useBean> 7. <jsp:setProperty> 8. <jsp:getProperty> 26 JEE - JSP & EL
  • 27. Standard action - <jsp:param> • It provides other tags with additional information as name value pairs • Used along with jsp:include, jsp:forward, jsp:plugin ! • Syntax: <jsp:param name=“parameter_name” value=“parameter_value” /> ! <jsp:param name=“parameter_name” value=“paramter_value> </jsp:param> 27 JEE - JSP & EL
  • 28. Standard action - <jsp:param> • Example: ! <jsp:param name=“font_color” value=“red” /> ! <jsp:param name=“font_color” value=“red”> <jsp:param> 28 JEE - JSP & EL
  • 29. Standard action - <jsp:include> • This allows to include a static or dynamic resource in the JSP at request time. • If page is buffered then the buffer is flushed prior to the inclusion • Syntax: <jsp:include page=“file_name” flush=“true|false”/> ! <jsp:include page=“file_name” flush=“true|false”> <jsp:param name=“parameter_name” value=“parameter_value”/> </jsp:include> 29 JEE - JSP & EL
  • 30. Example - <jsp:include> Student.jsp ! <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Student</title> </head> <body> <b><i>Student details:</i></b> <br> <% out.print(request.getParameter("name1") + " is taking the course of " + request.getParameter("course1")); %> <br> <% out.print(request.getParameter("name2") + " is taking the course of " + request.getParameter("course2")); %> </body> </html> 30
  • 31. Example - <jsp:include> StudentInfo.jsp! <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Student Information</title> </head> <body> <jsp:include page="Student.jsp"> <jsp:param value="Fabien" name="name1" /> <jsp:param value="JEE" name="course1" /> <jsp:param value="Antoine" name="name2" /> <jsp:param value="Java" name="course2" /> </jsp:include> </body> </html> 31
  • 32. Directive include vs Action include 32 JEE - JSP & EL Include Syntax Inclusion time Content type Parsing Directive <%@include file=“file_na me”%> Translation phase Static Container Action <jsp:include page=file_na me”%> Request processing phase Static or dynamic Not parsed, included in the container
  • 33. Standard action - <jsp:forward> • This is used to forward the request to another page ! • Syntax: <jsp:forward page=“file_name”/> ! <jsp:forward page=“file_name”> <jsp:param name=“parameter_name value=“paramater_value”/> </jsp:forward> 33 JEE - JSP & EL
  • 34. Standard action - <jsp:fallback> • Used in conjunction with <jsp:plugin> • This element can be used to specify an error string to be sent to the user in case the plugin fails ! • Syntax: <jsp:fallback> text message for user </jsp:fallback> 34 JEE - JSP & EL
  • 35. Standard action - <jsp:plugin> • Generates browser-specific code that makes an Object or Embed tag for the Java plugin • Can be used for applets and JavaBeans • Syntax: <jsp:plugin type=“bean|apple” code =“className.class” codebase=“path of className.class in WebRoot” [name= “name of bean or applet] [align=“bottom|top|middle|left|right] [height:”diplayPixels”] ….. > 35 JEE - JSP & EL
  • 36. Standard action - <jsp:plugin> [<jsp:params> <jsp:param name=“parameter_name” value=“parameter_value”/> <jsp:param name=“parameter_name” value=“parameter_value”/> ……. </jsp:params>] [<jsp:fallback> text message </jsp:fallback>] </jsp:plugin> 36 JEE - JSP & EL
  • 37. Standard action - <jsp:useBean> • It is used to find and instantiate a JavaBean • A common way of interaction between web pages • Scopes: • page: (default) within a JSP page • request: within the same request • session: all JSPs in the same session • application: within the same context 37 JEE - JSP & EL
  • 38. Standard action - <jsp:useBean> • Syntax: <jsp:useBean id= "bean_id" scope= "page | request | session | application" class= “packageName.className" beanName="packageName.className" > </jsp:useBean> 38 JEE - JSP & EL
  • 39. Standard action - <jsp:setProperty> • It is used to set the value of a bean’s property ! • Syntax: ! <jsp:setProperty name="bean_id" property= "*" | property="propertyName" param="parameterName" | property="propertyName" value="propertyValue" /> 39 JEE - JSP & EL
  • 40. Standard action - <jsp:getProperty> • It is used to retrieve the value of a bean’s property, convert it into a string and insert it into the output. ! • Syntax: <jsp:getProperty name=“bean_id” property=“propertyName”/> 40 JEE - JSP & EL
  • 41. JSP-JavaBeans Example package com.ece.jee; ! public class BackgroundColor { int red, blue, green; ! public BackgroundColor() { super(); this.red = 0; this.blue = 0; this.green = 255; } ! public int getRed() { return red; } ! public void setRed(int red) { this.red = red; } 41
  • 42. JSP-JavaBeans Example public int getBlue() { return blue; } ! public void setBlue(int blue) { this.blue = blue; } ! public int getGreen() { return green; } ! public void setGreen(int green) { this.green = green; } } 42
  • 43. JSP-JavaBeans Example <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:// www.w3.org/TR/html4/loose.dtd"> <jsp:useBean id="bgc" class="com.ece.jee.BackgroundColor" scope="session" /> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> ! <jsp:setProperty name="bgc" property="red" param="red" /> <jsp:setProperty name="bgc" property="green" param="green" /> <jsp:setProperty name="bgc" property="blue" param="blue" /> 43
  • 44. JSP-JavaBeans Example <body style="background: rgb(<jsp:getProperty name="bgc" property="red"/>, <jsp:getProperty name="bgc" property="green"/>, <jsp:getProperty name="bgc" property="blue"/>)"> <h3>Colorful Hello !!!</h3> ! <form name="colorForm" action="ColorExample.jsp" method="post"> Red: <input type="text" name="red"> Green: <input type="text" name="green"> Blue: <input type="text" name="blue"> <input type="submit"> </form> ! </body> </html> 44
  • 45. Initialization parameters In Deployment Descriptor: <servlet> <servlet-name>InitJSP</servlet-name> <jsp-file>/Example.jsp</jsp-file> <init-param> <param-name>userName</param-name> <param-value>Abcd</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>InitJSP</servlet-name> <url-pattern>/Example.jsp</url-pattern> </servlet-mapping> ! In JSP: Our initialization parameter has username value = <%= getServletConfig().getInitParameter("userName") %> 45 JEE - JSP & EL
  • 46. Overriding Init() <%! public void jspInit(){ String configUser = getServletConfig().getInitParameter("userName"); getServletContext().setAttribute("contextUser", configUser); } %> ! Our initialization parameter has username value = <%= config.getInitParameter("userName") %> <br/> Servlet context value for user = <%= application.getAttribute("contextUser") %> 46
  • 47. JSP Documents 47 JEE - JSP & EL
  • 48. Expression Language (EL) • Incorporated in JSP2.0 • Accessing bean using simple syntax • ${name} for a simple variable • ${name.foo.bar} for a nested property ! • Kinds of expressions • Arithmetic <jsp:setProperty name="box" property=“perimeter" value=“${2*box.width+2*box.height}"/> ! • Logical <c:if test="${bean1.a < 3}" > ... </c:if> 48 JEE - JSP & EL
  • 49. Operators in EL 49 JEE - JSP & EL Operator Description . Access a bean property or Map entry [] Access an array or List element ( ) Group a subexpression to change the evaluation order + Addition - Subtraction or negation of a value * Multiplication / or div Division % or mod Modulo (remainder)
  • 50. Operators in EL 50 JEE - JSP & EL Operator Description == or eq Test for equality != or ne Test for inequality < or lt Test for less than > or gt Test for greater than <= or le Test for less than or equal >= or gt Test for greater than or equal && or and Test for logical AND || or or Test for logical OR ! or not Unary Boolean complement empty Test for null, empty String, array or Collection. func(args) A function call
  • 51. Implicit Objects in EL 51 Implicit object Description pageScope Scoped variables from page scope requestScope Scoped variables from request scope sessionScope Scoped variables from session scope applicationScope Scoped variables from application scope param Request parameters as strings paramValues Request parameters as collections of strings header HTTP request headers as strings headerValues HTTP request headers as collections of strings initParam Context-initialization parameters cookie Cookie values pageContext The JSP PageContext object for the current page
  • 52. Implicit Objects in EL • Not the same as implicit objects of JSP • except pageContext ! • pageContext is used to access other JSP implicit objects ! • Syntax: ${pageContext.request.queryString} 52 JEE - JSP & EL
  • 53. Scope Objects • These scope objects allow access to variables stored at different access levels • requestScope • sessionScope • applicationScope • pageScope ! • Example Servlet context value for user = <%= application.getAttribute("contextUser") %> • Using EL Servlet context value for user = ${applicationScope.contextUser} 53 JEE - JSP & EL
  • 54. Handling Attributes • EL is used to read values, not to set values, JSP serves as “view” in MVC ! • In Servlet request.setAttribute(“contextUser”,cu); ! • Using EL ${requestScope[“contextUser”].name} ${sessionScope[“contextUser”].name} ${applicationScope[“contextUser”].name} 54 JEE - JSP & EL
  • 55. Param & ParamValues • Gives you access to parameter values using request.getParameter and request.getParameterValues methods ! • Example: for a parameter named password ${param.password} ${param[“password”]} 55 JEE - JSP & EL
  • 56. Getting Header Information • In JSP <%= request.getHeader(“host”)%> ! • With EL ${header.host} ${header[“host”]} 56 JEE - JSP & EL
  • 57. Init Parameter • Deployment Descriptor <context-param> <param-name>name</param-name> <param-value>Antoine</param-value> </context-param> ! • With expression
 <%= application.getInitParameter(“name”) %> ! • With EL ${initParam.name} 57 JEE - JSP & EL
  • 58. Accessing properties • If the expression has a variable followed by a dot, then this variable must be a bean or a map ! • Example: ${person.name} 58 JEE - JSP & EL “name”,”Fabien” name ! getName() setName() java.util.Map a bean
  • 59. Accessing properties • If the expression has a variable followed by a bracket, then this variable must be a bean, a map, a List or an Array ! • Example: ${person[name]} 59 JEE - JSP & EL “name”,”Fabien” name ! getName() setName() java.util.Map a bean 1. Fabien 2. Antoine 3. Serge 1.Fabien 2.Antoine 3.Serge an Array a List
  • 60. Array <%! String[] nameList = {"Alpha","Bravo","Charlie"}; %> ! <% request.setAttribute("name", nameList);%> Name : ${name} <BR /> Name : ${name[0]} <BR /> Name : ${name["0"]} 60 JEE - JSP & EL
  • 61. HashMap <%! Map<String,String> studentMap = new HashMap<String,String>(); %> ! <% studentMap.put("name","Fabien"); request.setAttribute("studentMap", studentMap); %> ! Name : ${studentMap.name} <BR /> Name : ${studentMap[name]} <BR /> Name : ${studentMap["name"]} 61 JEE - JSP & EL
  • 62. Requesting Parameters • In HTML <form action=“UserBean.jsp”>
 First Name : <input type=“text” name=“firstName”> Last Name: <input type=“text” name=“lastName”> <input type=“submit”> </form> ! • In JSP ${param.firstName} ${param.lastName} 62 JEE - JSP & EL
  • 63. 63 JEE - JSP & EL