[ Team LiB ] Previous Section Next Section

Implicit Objects

You should already be familiar with some of the implicit objects available to JSP scriptlets, such as request, response, and out. JSP EL has its own set of implicit objects that allows you to reference commonly -used data items quickly. You can use these objects in an expression as if they were variables.

The pageContext Object

The pageContext object gives you access to the pageContext JSP object. Through the pageContext object, you can access the request object. For example, to access the incoming query string for a request, you can use the expression:


Scope Objects

The pageScope, requestScope, sessionScope, and applicationScope variables provide access to variables stored at each scope level. Sometimes, the default search mechanism for locating variables isn't what you need. For example, suppose the variable product is located in both the request scope and the application scope. If you use the variable product in an expression, the JSP EL evaluator will use the closer scope, which is the request scope. If you need to explicitly access the product variable in the application scope, you can access it through the applicationScope variable as applicationScope.product.

param and paramValues Objects

The param and paramValues objects give you access to the parameter values normally available through the request.getParameter and request.getParameterValues methods. The reason you need a special object to access parameters is that they don't follow the normal JavaBean format for attributes. Both of these methods take a string argument, which is not an allowable form for a bean's get method.

For example, to access a parameter named order, use the expression ${param.order} or ${param["order"]}.

The param object returns single string values, whereas the paramValues object returns string arrays (if there is only one parameter value, paramValues returns an array of length 1).

header and headerValues Objects

The header and headerValues objects give you access to the header values normally available through the request.getHeader and request.getHeaders methods, similar to the way param and paramValues give you access to parameters. The header method returns a single header value, whereas the headerValues object returns an array of values.

To access the header value user-agent, use the following expression:


The cookie Object

The cookie object gives you access to the session cookies normally available through the session.getCookies method. For example, to access a cookie named lastOrder, use this expression:

    [ Team LiB ] Previous Section Next Section