EL Implicit Object pageContext

 pageContext   

     


Introduction:

1.  This is the only one EL implicit object which matches with Jsp implicit objects.
2.  By using this implicit object we can bring all other implicit objects into EL and accessing servlet and JSP properties, such as a request's protocol or server port, or the major and minor versions of the servlet API your container supports.
3.  You can find out that information and much more with the pageContext implicit object, which gives you access to the request, response, session, and application (also known as the servlet context).
4.  Useful properties for the pageContext implicit object are listed in Table 2.6.

Property
Type
Description
request
ServletRequest
The current request
response
ServletResponse
The current response
servletConfig
ServletConfig
The servlet configuration
servletContext
ServletContext
The servlet context
session
HttpSession
The current session

Ex: 1.${pageContext.request.method}
       2.${pageContext.session.id}

     

EL Implicit Object initParam

initParam

     


By using this implicit object we can access context initialization parameters.

 ExpressionLanguage
Jsp  code
initParam.user
application.getInitParameter ( “user”)

Ex: ${initParam.user}   Output : scott
        ${initParam.pwd}   Output:Blank space.
Add this piece of code in web.xml

<context-param>
          <param-name>user</param-name>
          <param-value>chamu0001</param-value>
</context-param>
<context-param>
          <param-name>password</param-name>
          <param-value>myjavahub</param-value>
</context-param>
 test.jsp

<%@ page isELIgnored="false" %>
<%
Cookie cookie = new Cookie ("username","chamu");
cookie.setMaxAge(60 * 60);
response.addCookie(cookie);
%>
<table border= 2>
<tr><td><h2>initParam.user</h2></td> <td><h2>${initParam.user}</h2></td></tr>
<tr><td><h2>initParam.password</h2></td> <td><h2>${initParam.password}</h2></td></tr>
</table>

Output:  http://localhost:8080/Scwcd_jsp/test.jsp


             

EL Implicit Object cookie


Cookie

                                                          
We can use this implicit object to retrieve cookies associated with the request.
Example :${cookie.JSESSIONID}
                 ${cookie.JSESSIONID.name}
                 ${cooke.JSESSIONID.value}
test.jsp

<%@ page isELIgnored="false" %>
<%
Cookie cookie = new Cookie ("username","chamu");
cookie.setMaxAge(60 * 60);
response.addCookie(cookie);
%>
<table border= 2>
<tr><td><h2>${cookie.username.name}</h2></td> <td><h2>${cookie.username.value}</h2></td></tr>
<tr><td><h2>${cookie.JSESSIONID.name}</h2></td> <td><h2>${cookie.JSESSIONID.value}</h2></td></tr>
</table>

First Request:

 Second Request: 



      

EL Implicit Object header & headerValues


                   header & headerValues      
                                  
                                                            
The header and headerValues objects are used to retrieve the header values normally available through the request.getHeader and request.getHeaders methods.
Ex: To access a header named user-agent, use the expression${header.user-agent} or ${header["user-agent"]}.

${header.accept}
${headerValues.accept[0]}

test.jsp

<%@ page isELIgnored="false" %>
<table border = 2>
<tr><td>header.cookie :</td><td>${header.cookie}</td></tr>
<tr><td>header.connection</td><td>${header.connection}</td></tr>
<tr><td>headerValues.host[0]</td><td>${headerValues.host[0]}</td></tr>
<tr><td>headerValues.accept[0]</td><td>${headerValues.accept[0]}</td></tr>
<tr><td>header.user-agent</td><td>${header.user-agent}</td></tr>
</table>

Output: http://localhost:8080/Scwcd_jsp/test.jsp