The document discusses JavaServer Pages (JSP) and the Expression Language (EL) in JEE. It covers key JSP concepts like scripting elements, directive elements, standard action elements, and implicit objects. It also explains the translation of JSP files to servlets, and provides examples of using scripting elements, directives like <jsp:include>, and standard actions.
This slide is about basics of java servlet and java server page.
A basic example of JSP using multiple directives.
Further information of setting up and using of Apache Tomcat server.
This slide is about basics of java servlet and java server page.
A basic example of JSP using multiple directives.
Further information of setting up and using of Apache Tomcat server.
JAVA EE DEVELOPMENT (JSP and Servlets)Talha Ocakçı
Java and J2EE is the most used technologies in enterprise web development. Telecom operators, service providers are using these technlogies; banking and insurance companies are moving to Java from old generation technologies.
https://www.udemy.com/java-web-developmen-with-real-world-development-flow
If you want to earn much in web development business, you also need to learn Java web technologies.
Java has de facto standart frameworks such as EJB 3.0, Spring and others that can be bound to them.
But at heart, they all use the similar JSP/Servlet technology and add some layers above them to speed up the development.
You will use them in your daily business but before using them, you must learn the basics and what is going on while using them. Otherwise, you will not be able to find a proper solution to common problems.
This course will make you understand the basics of JSP / servlet technlogies, designing a relational database, DB operations, design patterns, working with other developers,
and let you know the must-do operations in professional projects such as performance increasing, logging errors.
If you want to develop a web-site in a couple of hours without understanding what you are doing, you may go ahead and find other resources. But if you really want to understand what you are doing and learn the theory at the same time, this course will be a great oppurtunity for you. You will develop a real working project. Yow will first write quick and dirty code then you will apply professional patterns one by one while investigating the problems.
You will walk through a real development flow:
1- Write a quick and dirty code for doing the job.
2- You will design database tables and high performance queries
3 - You will apply design patterns to make the code reusable and high performance.
4 - You will beautify the user interface with Javascript and CSS tweaks
5- You will add exception handling, logging mechanism for production environment
6- AT THIS STEP, YOU WILL BE HIRED FOR MUCH MUCH HIGHER SALARIES. BECAUSE YOU ARE A REAL PROFESSIONAL.
Its an distributed enviornment for developing the enterprise application.We can develop multi-tier,three-tier or n-tier architecture using this.In this Java Server Pages and Servlet is the important things
The Web and Spring MVC continue to be one of the most active areas of the
Spring Framework with each new release adding plenty of features and refinements
requested by the community. Furthermore version 4 added a significant choice
for web applications to build WebSocket-style architectures.
This talk provides an overview of the areas in which the framework has evolved
along with highlights of specific noteworthy features from the most recent
releases.
Overview of EJB technology.
Enterprise Java Beans (EJB) is a server-side component technology for Java EE based systems (JEE).
Beans are business logic components that implement a standard interface through which the bean is hooked into the bean container (= runtime object for bean).
A Java class implementing one of the standard bean interfaces is an Enterprise Java Bean. Beans can be accessed remotely, usually from a client tier.
The EJB standard was developed to provide a common framework for solving recurring problems in business application development like persistence, transactions,
security and runtime and lifecycle management. The EJB standard evolved greatly over time. EJB version 1 and 2 were complex and required to implement many interfaces
and exception handling in EJBs. EJB version 3 brought great simplifications and did away with interfaces by replacing these with annotations which provide greater flexibility while keeping complexity low. EJBs come in 3 different flavors: Stateless and stateful session beans and message driven beans. Entity beans of EJB version 1 and 2 were replaced by the Java Persistence API in EJB version 3.
JAVA EE DEVELOPMENT (JSP and Servlets)Talha Ocakçı
Java and J2EE is the most used technologies in enterprise web development. Telecom operators, service providers are using these technlogies; banking and insurance companies are moving to Java from old generation technologies.
https://www.udemy.com/java-web-developmen-with-real-world-development-flow
If you want to earn much in web development business, you also need to learn Java web technologies.
Java has de facto standart frameworks such as EJB 3.0, Spring and others that can be bound to them.
But at heart, they all use the similar JSP/Servlet technology and add some layers above them to speed up the development.
You will use them in your daily business but before using them, you must learn the basics and what is going on while using them. Otherwise, you will not be able to find a proper solution to common problems.
This course will make you understand the basics of JSP / servlet technlogies, designing a relational database, DB operations, design patterns, working with other developers,
and let you know the must-do operations in professional projects such as performance increasing, logging errors.
If you want to develop a web-site in a couple of hours without understanding what you are doing, you may go ahead and find other resources. But if you really want to understand what you are doing and learn the theory at the same time, this course will be a great oppurtunity for you. You will develop a real working project. Yow will first write quick and dirty code then you will apply professional patterns one by one while investigating the problems.
You will walk through a real development flow:
1- Write a quick and dirty code for doing the job.
2- You will design database tables and high performance queries
3 - You will apply design patterns to make the code reusable and high performance.
4 - You will beautify the user interface with Javascript and CSS tweaks
5- You will add exception handling, logging mechanism for production environment
6- AT THIS STEP, YOU WILL BE HIRED FOR MUCH MUCH HIGHER SALARIES. BECAUSE YOU ARE A REAL PROFESSIONAL.
Its an distributed enviornment for developing the enterprise application.We can develop multi-tier,three-tier or n-tier architecture using this.In this Java Server Pages and Servlet is the important things
The Web and Spring MVC continue to be one of the most active areas of the
Spring Framework with each new release adding plenty of features and refinements
requested by the community. Furthermore version 4 added a significant choice
for web applications to build WebSocket-style architectures.
This talk provides an overview of the areas in which the framework has evolved
along with highlights of specific noteworthy features from the most recent
releases.
Overview of EJB technology.
Enterprise Java Beans (EJB) is a server-side component technology for Java EE based systems (JEE).
Beans are business logic components that implement a standard interface through which the bean is hooked into the bean container (= runtime object for bean).
A Java class implementing one of the standard bean interfaces is an Enterprise Java Bean. Beans can be accessed remotely, usually from a client tier.
The EJB standard was developed to provide a common framework for solving recurring problems in business application development like persistence, transactions,
security and runtime and lifecycle management. The EJB standard evolved greatly over time. EJB version 1 and 2 were complex and required to implement many interfaces
and exception handling in EJBs. EJB version 3 brought great simplifications and did away with interfaces by replacing these with annotations which provide greater flexibility while keeping complexity low. EJBs come in 3 different flavors: Stateless and stateful session beans and message driven beans. Entity beans of EJB version 1 and 2 were replaced by the Java Persistence API in EJB version 3.
С тех пор как компания Sun в 1997 году представила технологию EJB широкой общественности, вокруг нее успел сложиться очень мощный и развитый сектор серверных технологий, включающий помимо EJB такие технологие как: сервлеты (servlets), JMS (Java Messaging Service), JSP (Java Server Pages), JCA (Java Connectors Architecture), JDBC (Java Database Connectivity), JAAS (Java Authorization & Authentication System), а также технологии управления транзакциями и многие другие. Наличие всех этих технологией, к тому-же объединенных общей идеологией делает платформу J2EE в целом и технологию EJB в частности, крайне привлекательным решением.
The Modern Java Web Developer Bootcamp - Devoxx 2013Matt Raible
HTML5, CSS3, JavaScript, jQuery, Angular JS, Bootstrap, Mobile, CoffeeScript, GitHub, functional programming, Page Speed, Apache, JSON with Jackson, caching, REST, Security, load testing, profiling, Wro4j, Heroku, Cloudbees, AWS.
These are just some of the buzzwords that a Java web developer hears on a daily basis. This talk is designed to expose you to a plethora of technologies that you might've heard about, but haven't learned yet. We'll concentrate on the most important web developer skills, as well as UI tips and tricks to make you a better front-end engineer. Some of the most valuable engineers these days have front-end JS/CSS skills, as well as backend Java skills.
This presentation is from the University session I delivered at Devoxx 2013, in Antwerp. http://devoxx.be/dv13-matt-raible.html?presId=3648
JSP AND XML USING JAVA WITH GET AND POST METHODSbharathiv53
This ppt contains JSP life cycle, Tags, Tomcat, Request String,
User Sessions, Cookies, Session Objects; XML - Tags, Elements,
Attributes, XML with CSS, XML and DTD (Document Type Definition),
XML Schema.
JSP technology is used to create web application just like Servlet technology. It can be thought of as an extension to Servlet because it provides more accuracy.
A JSP page consists of HTML tags and JSP tags. The JSP pages are easier to maintain than Servlet because we can separate designing and development. It provides some additional features such as Expression Language, Custom Tags, etc. Extension to Servlet, Easy to maintain, Fast Development: No need to recompile and redeploy, Less code than Servlet
Tutorial 2 - Basics of Digital PhotographyFahad Golra
In the first session of this 5 session workshop, I am going to explain the photography gear (camera) with special focus on different sensor types. Then we will discuss about the fundamental concepts of photography.
Tutorial 1 - Basics of Digital PhotographyFahad Golra
In the second session of this 5 session workshop, I am going to explain the photography gear (lens) with special focus on focal length and maximum aperture. Then we will discuss about the introduction of exposure in photography.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Introduction to AI for Nonprofits with Tapp Network
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
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
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
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
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