JSP Implicit Objects: 9 Implicit Objects in JSP

In the previous tutorial, we have learned JSP Scripting Elements with Example. In this tutorial, we will learn about JSP implicit objects with Example. Basically, there are 9 implicit objects in JSP. We will learn all these implicit objects in detail. But first, understand what is JSP implicit objects?

What is 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 translating 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.

Read: JSP Scripting Elements with Example

9 implicit objects in JSP:

1. out: 

It is used for writing content to the client browser. It is an object of 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 parameter, header information, content type, server name, etc.

JSP Implicit Objects


JSP Implicit Objects




3. response:

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

JSP Implicit Objects


JSP Implicit Objects


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


JSP Implicit Objects


JSP Implicit Objects

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 deployment descriptor(web.xml) file.

JSP Implicit Objects


JSP Implicit Objects


JSP Implicit Objects

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


JSP Implicit Objects

JSP Implicit Objects

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 session scope.

JSP Implicit Objects


JSP implicit objects

JSP Implicit Objects

JSP implicit objects


JSP implicit objects

JSP implicit objects


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 JSP error page.

JSP Implicit Objects: 9 Implicit Objects in JSP JSP Implicit Objects: 9 Implicit Objects in JSP Reviewed by Prashant Srivastava on November 09, 2018 Rating: 5

No comments:

Powered by Blogger.