This document discusses JavaBeans and the Expression Language (EL) in Java Server Pages (JSP). It describes how JavaBeans are reusable Java components that follow conventions for properties and methods. The EL allows easier access to JavaBeans properties without scripting code. It provides implicit objects to access attributes, request parameters, cookies and context initialization parameters. The EL supports operators and functions for conditions and evaluations.
3. javaBeans (not EJB)
• reusable software components
• classes written in Java conforming to a particular convention
• used to encapsulate many objects into a single object (the
bean), so that they can be passed around as a single bean
object
• a Java Object that
• is serializable,
• has a nullary constructor, and
• allows access to properties using getter and setter methods.
21. Expression Language (EL)
A scripting language which allows easier
access to JavaBeans through JSP.
Access Java objects without using Java
Widely spread
29. Back to EL implicit
objects
M
aps
to
scope
attributes
M
aps
to
requestparam
s
M
ap
ofcookies
M
aps
to
requestheaders
M
ap
ofcontextinnate
param
s
reference
to
object
31. Getting useful staff
• Scripting
• Host is: <%= request.getHeader(“host”) %>
• Method is: <%= request.getMethod() %>
• EL
• Host is: ${header[“host”]}
• Host is: ${header.host}
• Method is: ${request.method}
• Method is: ${requestScope.method}
• Method is: ${pageContext.request.method}
Gives attributes
(not properties)
There is
no such
implicit
object
32. Prefacing attributes
• Control scoping
${person.name} or ${requestScope.person.name}
• Avoid problems with the name’s string nature
request.setAttribute(“person”, p);
request.setAttribute(“foo.person”, p);
${foo.person.name}
${requestScope[“foo.person”].name}
33. Cookies & init
params
<% Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++)
{ if ((cookies[i].getName()).equals(“userName”)) {
out.println(cookies[i].getValue());
}
} %>
${ cookie.userName.value}
<context-param>
<param-name>mainEmail</param-name>
<param-value>likewecare@wickedlysmart.com </param-value>
</context-param>
email is: <%= application.getInitParameter(“mainEmail”) %>
email is: ${ initParam.mainEmail}