JSP Implicit Objects: 9 Implicit Objects in JSP | Complete Tutorial on Implicit Objects in JSP

In the earlier tutorial, we have seen JSP Scripting Elements with Example. In this tutorial, we will discuss & understand JSP implicit objects with examples. Primarily, there are 9 implicit objects in JSP. Let’s learn all these implicit objects in detail. But first, learn what is JSP implicit objects?

This Implicit Objects in JSP Tutorial Contains: 

What are JSP Implicit Objects?

Implicit objects are the set of predefined objects readily available for use. These objects are created by the JSP container, while a JSP page translates into Servlet. Implicit Objects are being created inside the service() method so we can use implicit objects directly within scriptlets without initializing and declaring them. Total 9 Implicit objects are available in JSP.

Implicit Objects and their corresponding classes

out javax.servlet.jsp.JspWriter
request javax.servlet.http.HttpServletRequest
response javax.servlet.http.HttpServletResponse
session javax.servlet.http.HttpSession
application javax.servlet.ServletContext
exception javax.servlet.jsp.JspException
page java.lang.Object
pageContext javax.servlet.jsp.PageContext
config javax.servlet.ServletConfig

Also Check: 

How many Implicit Objects are available in JSP?

There are 9 types of implicit objects available in the container:

  1. out
  2. request
  3. response
  4. page
  5. pageContext
  6. config
  7. application
  8. session
  9. exception

Let’s check out one by one from the below sections:

1. out:

It is used for writing content to the client browser. It is an object of the JSP Writer. In servlet you need to write PrintWriter out = response.getWriter() for writing content to the browser, but in JSP you don’t need to write this.

2. request:

It is an object of HttpServletRequest.This object is created for each JSP request by the web container. The main purpose of this object is to get the data on a JSP page which is entered by the user. This object is used to get request information like a parameter, header information, content type, server name, etc.

JSP Implicit Objects 9 Implicit Objects in JSP 1

JSP Implicit Objects 9 Implicit Objects in JSP 2

JSP Implicit Objects 9 Implicit Objects in JSP 3

JSP Implicit Objects 9 Implicit Objects in JSP 4

3. response:

It is an object of HttpServletResponse. This object will be created by the container for each request. We can use the response object to set content type, adding cookies, and redirecting the request to another resource.

JSP Implicit Objects 9 Implicit Objects in JSP 5

JSP Implicit Objects 9 Implicit Objects in JSP 6

4. page:

JSP page implicit object is an object of java.lang.Object class. This object represents the current JSP page. It is rarely used. It provides a reference to the generated servlet class.

5. pageContext:

JSP pageContext object is an object of javax.servlet.jsp.PageContext class. It is used for accessing page, application, request and session scope.

JSP Implicit Objects 9 Implicit Objects in JSP 7

JSP Implicit Objects 9 Implicit Objects in JSP 8

JSP Implicit Objects 9 Implicit Objects in JSP 9

6. config:

JSP config implicit object is an instance of java.servlet.ServletConfig class. This object is created by the container for each JSP page. It is used to get the initialization parameter in the deployment descriptor(web.xml) file.

JSP Implicit Objects 9 Implicit Objects in JSP 10

JSP Implicit Objects 9 Implicit Objects in JSP 11

JSP Implicit Objects 9 Implicit Objects in JSP 12

7. application:

JSP application implicit object is an instance of java.servlet.servletContext class.It is used to obtain the context information and attributes in JSP.The servlet context obtained from the servlet configuration object by using the getServletConfig().getServletContext() method.One application object is created by the container for one JSP application when the application is deployed.

JSP Implicit Objects 9 Implicit Objects in JSP 13

JSP Implicit Objects 9 Implicit Objects in JSP 14

JSP Implicit Objects 9 Implicit Objects in JSP 15

8. session:

JSP Session implicit object is an instance of javax.servlet.http.HttpSession class.The session object is created for the requesting clients(if any). This variable is only valid for HTTP-based protocol. we can use this object to get, set, and remove an attribute from the session scope.

JSP Implicit Objects 9 Implicit Objects in JSP 16

JSP Implicit Objects 9 Implicit Objects in JSP 17

JSP Implicit Objects 9 Implicit Objects in JSP 18

JSP Implicit Objects 9 Implicit Objects in JSP 19

JSP Implicit Objects 9 Implicit Objects in JSP 20

JSP Implicit Objects 9 Implicit Objects in JSP 21

9. Exception:

JSP exception implicit object is an instance of java.lang.Throwable class. It is used for exception handling in JSP. It can be only used for the JSP error page.

Leave a Comment