Learn Java for Web Development

(Tina Meador) #1

124 CHAPTER 3: Best Practices in Java EE Web Development


Using EL Implicit Objects


Of the EL implicit objects listed in Table 3-3, applicationScope, pageScope, requestScope, and
sessionScope are meant for specifying scope. These are used to access scoped attributes, that is,
to access data from JavaBeans, maps, arrays, and lists that have been stored as attributes in any of
the four scopes: page, request, session, and application.


The other implicit objects listed in Table 3-3 are used to access request parameters, request
headers, cookies, context-initialization parameters, and pageContext objects. This section illustrates
the usage of some of the EL implicit objects.


Accessing Request Parameters


Listing 3-24 illustrates a simple form used to submit the request parameters through form.jsp.


Listing 3-24. form.jsp


1.
2.


3.
4.

Book Title:


5.

Author 1 Name:


6.

Author 2 Name:


7.
8.
9.

10.


In Listing 3-24, the name property of the tag is the same: authorName.


Listing 3-25 illustrates the usage of the EL implicit objects param and paramValues to retrieve the
request parameter and display the result on the result.jsp page.


Listing 3-25. result.jsp


1.

Book Title: ${param.bookTitle}

2.Author 1: ${paramValues.authorName[0]}

3.Author 2: ${paramValues. authorName[1]}
4.


   Line 1: This uses the EL implicit object param to get the Book title.
 Line 2 to Line 3: This code uses the EL implicit object paramValues to get the
Author 1 and Author 2 names.

Accessing the Header


The EL implicit objects header and headerValues give you access to the header values that can be
obtained using the request.getHeader() and request.getHeaders() methods.

Free download pdf