JSP Implicit Objects

In most cases, you use the JSP expression language in conjunction with the Model View Controller (MVC) architecture in which the servlet creates the data and the JSP page displays the data. In such a scenario, the JSP page is only interested in the objects that the servlet created and the general bean access and collection access mechanisms are sufficient. Hence, implicit objects are created by the web container that is available to all the JSP pages. There are in total 9 Implicit objects

A list of the 9 implicit objects is given below:

Implicit ObjectCrossponding class
outjavax.servlet.jsp.JspWriter
requestjavax.servlet.http.HttpServletRequest
responsejavax.servlet.http.HttpServletResponse
sessionjavax.servlet.http.HttpSession
applicationjavax.servlet.ServletContext
exceptionjavax.servlet.jsp.JspException
pagejava.lang.Object
pageContextjavax.servlet.jsp.PageContext
configjavax.servlet.ServletConfig

out

It is used to write/print content in the browser.

Example:

out.print("Hello, Coder Sathii");

request

It is to get the data on a current JSP page that has been requested by the previous JSP page.

Example:

String name= request.getParameter("name");

response

Response object helps the user to give the response to the client after page load.

Example:

response.sendRedirect("codersathi.com");

session

It is used for storing users’ data to make it available on other JSP pages till the user session is active.

Example:

session.setAttribute(“name”);
session.getAttribute(“name”);

application

It is used for getting application-wide initialized parameter(s) and to maintain useful data across whole JSP application.

Example:

application.getAttribute(“RadhaKrishnan”);

exception

The exception object is used to handle an exception for displaying the error messages. This object is only available to the JSP pages, which have isErrorPage set to true.

Example:

<!-- errorPage.jsp -->

<%@ page isErrorPage="true" %>

Exception occurred: <%= 25/0 %>

page

The page implicit object represents the JSP page itself. It is of type object and is rarely used in JSP pages.

pageContext

The pageContext implicit object provides methods to access other implicit objects. Specifically pageContext object has methods like getPage, getRequest, getResponse etc. It also provides methods to set and get attributes. The scope of the pages attribute is to process of that page.

config

This is a Servlet configuration object and mainly used for accessing getting configuration information such as servlet context, servlet name, configuration parameters etc.

Example:

String servletName=config.getServletName();

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments