Working With Implicit EL Object


Implicit Expression Language Objects In JSP:

The most useful feature of the JSTL Expression Language is the implicit objects. It defines for accessing all kinds of application data. JSP developers can directly use implicit objects in an EL expression. They do not need to write extra code for using these objects. some of these objects allow the access to variables held in the particular JSP scopes. All these objects map the respective scope attribute names to their values. 

The JSP Expression Language defines various implicit objects:

Objects Name                       Description
pageContext  The instance of pageContext is used to manipulate page attributes  
  access servletContext, session, request, response objects        
requestScope  Maps request-scoped variable names to their values
sessionScope  Maps session-scoped variable names to their values
applicationScope  Maps application-scoped variable names to their values
param  Maps a request parameter name to a single value
param values  Maps a request parameter name to an array of values
Header  Maps a request header name to a single value
headerValues  Maps a request header name to an array of values
cookie  Maps a cookie name to a single cookie
initParam  Maps a context initialization parameter name to a single value

There are three types of  implicit EL  objects:

  • Maps for a single set of values, such as request headers and cookies:
    param, paramValues, header, headerValues, initParam, cookie
  • Maps for scoped variables in a particular scope:
    pageScope, requestScope, sessionScope, applicationScope
  • The page context: pageContext


Example:
Using implicit EL Objects:
In this example the user is asked to enter some information and then that information is and
           displayed along with other information.       
               
1.Index.jsp:
   
 
<html>
       <body bgcolor="cyan">
         <form action="imobjects2.jsp" method="get">
         <table border="2">
         <tr><th>Using Implicit Objects</th></tr>
         <tr><td colspan="2"><h3>pet shopping cart</h3></td></tr>
         <tr><td>
           Your Email Id:<input type="text" name="email" size="30" /> </td>
         </tr>
         <tr><td>Whats Type of Pet do you have?
         </td></tr>
         <tr><td>Cat<input type="checkbox" name="pettype" value="cat"/>
         </td></tr>
         <tr><td>Dog<input type="checkbox" name="pettype" value="dog"/>
         </td></tr>
         <tr><td>Rabbit<input type="checkbox" name="pettype" value="rabbit"/>
         </td></tr>
         <tr><td>Goat<input type="checkbox" name="pettype" value="goat"/>
         </td></tr>
         <tr><td>Sheep<input type="checkbox" name="pettype" value="sheep"/>
         </td></tr>
         <tr><td>Horse<input type="checkbox" name="pettype" value="horse"/>
          </td></tr>
         </table>
         <tr><td><input type="submit" value="Submit" ></td><tr>
         </table>
         </form>
         </
body>
   
</html>

  2.The impobject2.jsp:

    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  <html>
    <head>
      <title>Using Implicit Objects</title>
    </head>
      <body bgcolor="pink"><table border="2" align="center">
       <tr><th>Using Implicit Objects</th></tr></table>
       <p><ul>
       <li><b>Your Email Id Is:</b>${param.email}
       <li><b>You have selected pest:</b>
       <c:forEach var="pet" items="${paramValues.pettype}">
        &nbsp;&nbsp;&nbsp;&nbsp;${pet}
        &nbsp;&nbsp; </c:forEach>
       <li><b>User-Agent Header:</b> ${header["User-agent"]}
       <li><b>JSESSIONID Cookie value:</b>${cookie.JSESSIONID.value}
       <li><b>Server:</b>${pageContext.servletContext.serverInfo}
       </ul>
      </body>
    </html>

OUTPUT:

1.Index.jsp:

  index.gif

2.The impobject2.jsp:

  import.gif    


Similar Articles