Expression Language Implicit Variables in JSP.

How are Implicit Variables used in JSP?

Explanation

Implicit variables are those which are instantiated automatically and are references to objects created by the JSP EL language. These are provided by default by the JSP container.

Following are the list of implicit objects provided by JSP.
Variables Description
pageScope Collection of all page scope variables
requestScope Collection of all request scope variables
sessionScope Collection of all session scope variables
applicationScope Collection of all application scope variables
param Collection of all request parameter as single string value per parameter
paramValue Collection of all request parameter as string array per parameter
header Collection of all request header values as a single string value per header
headerValues Collection of all request header values as string array per header.
cookie Collection of all request cookie values as javax.servlet.http.Cookie value per cookie
intiParam Collection of all application intialization parameter as single string value per value
pageContext Instance of javax.servlet.jsp.Pagecontext class to access various request data.

Example :


<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"
prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
<html>
<body>
<form action="implicit1.jsp" method="GET">
NAME:<input type="text" name="nam">
<input type="submit">
</form>
<p><b>NAME</b>
: ${param.nam}</p>
<p><b>HEADER</b>
: ${header["host"]}</p>
<p><b>USER AGENT</b>:${header["user-agent"]}</p>
</html>
Result :

NAME : alex
HEADER : localhost:8080
USER AGENT:Mozilla/5.0 (Windows; U; Windows NT 5.1;
en-US; rv:1.9.0.15)Gecko/2009101601 Firefox/3.0.15
GTB5

In the above example we have used the implicit variables "param" and "header" to display the name entered, header, browser details etc.

Ask Questions

Ask Question