Skip to content
  • Facebook
GeekCer Logo

GeekCer

The geek's Coding education and Review centre

  • Home
  • Tutorials
    • Java
    • Servlet
    • JSP
    • Python
    • C Tutorial
    • Spring
    • Spring Boot
    • MongoDB
    • Hibernate
    • Data Structure
  • General Knowledge
  • Biography
  • Grammar
  • Festival (त्योहार)
  • Interview
  • Differences
  • Important
  • Toggle search form

Home » JSP » JSP Implicit Objects

  • Kishkindha Kand in Hindi | Ram meets Hanuman | किष्किंधा कांड
    Kishkindha Kand in Hindi | Ram meets Hanuman | किष्किंधा कांड Spiritual
  • Jagannath Rath Yatra History in Hindi | जगन्नाथ पुरी की कहानी
    Jagannath Rath Yatra History in Hindi | जगन्नाथ पुरी की कहानी Festival
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
    Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी Biography
  • Impeachment meaning in Hindi | महाभियोग की परिभाषा और प्रक्रिया
    Impeachment meaning in Hindi | महाभियोग की परिभाषा और प्रक्रिया General Knowledge
  • America Independence Day : 4th July USA | USA Birthday
    America Independence Day : 4th July USA | USA Birthday General Knowledge
  • Mahatma Gandhi Essay in Hindi | Gandhiji Biography
    Mahatma Gandhi Essay in Hindi | Gandhiji Biography Biography
  • Fundamental Duties of Indian Citizens
    Fundamental Duties of Indian Citizens | 11 मौलिक कर्तव्य हिंदी में General Knowledge
  • State the Universal law of gravitation | Law of Gravity, Formula
    State the Universal law of gravitation | Law of Gravity, Formula Science

JSP Implicit Objects

Posted on September 6, 2021October 20, 2021 By GeekCer Education No Comments on JSP Implicit Objects
JSP Implicit Objects

JSP Implicit objects are variables which we can use directly in scriptlets. The web container creates the objects automatically. In the translation phase from JSP to Servlet, the web container creates these objects.

We do not need to explicitly create and we don’t need to declare and initialize because objects are created within service method so that we can access them directly. You can also use these objects inside the JavaBeans and Servlets.

In this article you will learn about JSP implicit object and their types in detail. You can get examples of most of the contained objects from this article.

Table of Contents

  • Types of JSP Implicit Objects
    • 1) out implicit object
      • Example of out implicit object
    • 2) request implicit object
      • Example of request implicit object
    • 3) response implicit object
      • Example of response implicit object
    • 4) config implicit object
    • 5) application implicit object
      • Example of application implicit object
    • 6) session implicit object
      • Example of session implicit object
  • 7) exception implicit object
    • Example of exception implicit object
    • 8) page implicit object
  • 9) pageContext implicit object

Types of JSP Implicit Objects

There are 9 types of implicit objects available.

1) out implicit object

The out implicit object is an instance of a javax.servlet.jsp.JspWriter. We can use out object to write the data to the buffer and send output to the browser.

javax.servlet.jsp.JspWriter has some methods which are as follows:

#MethodDescription
1out.print()Prints the data type value.
2out.println()Prints the data type value with new line character.
3out.flush()Flushes the stream.

Example of out implicit object


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
  int firstValue = 100;
  int secondValue = 200;
  out.println("firstValue is " + firstValue);
  out.println("secondValue is " + secondValue);
%>

</body>
</html>

2) request implicit object

We use this object to get client information. Client information may include form data, cookies, http methods and so on. The request object is an instance of java.servlet.http.HttpServletRequest.

We access the request parameters using the getParameter() method.

Example of request implicit object

index.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="output.jsp">
<input type="text" name="name">
<input type="submit" value="Submit">
</form>

</body>
</html>

output.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
  String requestedName = request.getParameter("name");
  out.println(requestedName);
%>

</body>
</html>

3) response implicit object

We use this object to set content type, add cookie and redirect to page. This object represents the response that we give to the client.

The response object is an instance of java.servlet.http.HttpServletResponse.

Example of response implicit object

index.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="output.jsp">
<input type="submit" value="Submit">
</form>

</body>
</html>

output.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
  response.sendRedirect("https://geekcer.com");
%>

</body>
</html>

4) config implicit object

You can get configuration information for JSP page, you can get initialization parameter from servlet and you can also get path or file location of JSP. The config object is an instance of javax.servlet.ServletConfig.

web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	id="WebApp_ID" version="3.0">
	<display-name>JspTutorials</display-name>
	<servlet>
		<servlet-name>GeekServlet</servlet-name>
		<jsp-file>/index.jsp</jsp-file>
	</servlet>
	<servlet-mapping>
		<servlet-name>GeekServlet</servlet-name>
		<url-pattern>/index</url-pattern>
	</servlet-mapping>
</web-app>

output.xml


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
  String servletName = config.getServletName();
  out.print("Servlet Name is: " + servletName);
%>

</body>
</html>

5) application implicit object

The Application object is an instance of javax.servlet.ServletContext and when the application is deployed, one instance is created per application.

Example of application implicit object

index.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
  Integer counter = (Integer) application.getAttribute("visitorCount");
  if (counter == null || counter == 0) {
    counter = 1;
  } else {
    counter = counter + 1;
  }
  out.println("Visitor: " + counter);
  application.setAttribute("visitorCount", counter);
%>

</body>
</html>

6) session implicit object

We can get session information and we can also get, set and remove attributes in the session. We use session object when we need to track client session between client requests then you should go for session object. The session object is an instance of javax.servlet.http.HttpSession.

Example of session implicit object

index.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
session.setAttribute("name","GeekCer"); 
%>
<a href="welcome.jsp">Click here to get Name</a>

</body>
</html>

welcome.jsp


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
String name = (String)session.getAttribute("name");
out.println("Name is " + name);
%>

</body>
</html>

7) exception implicit object

The exception object is an instance of java.lang.Throwable and we use this object in exception handling to display the error.

Example of exception implicit object


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isErrorPage="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

Exception occured:<%= exception %>

</body>
</html>

8) page implicit object

It is an object that represents the entire JSP page. The page is an instance of the java.lang.object class. The work of page in JSP is similar as this keyword in java. It is an instance of java.lang.Object.

9) pageContext implicit object

It is an instance of javax.servlet.jsp.PageContext. We can use this object to get attribute, get attribute, set attribute and remove attribute at the level of JSP Page, HTTP request, HTTP session and Application level.

In conclusion, in this article you have learned about the jsp Implicit objects in details with their example program. If you have any query regarding this article, you can write to us at geekcer.code@gmail.com. Hope you liked this post about implicit object.

You can freely give your valuable feedback and comments here.

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • More
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Also Read

JSP

Post navigation

Previous Post: JSP Directives
Next Post: HTTP status codes List | Response Status Code Glossary

More Related Articles

JSP Scripting Tags (Scripting Elements) JSP Scripting Tags (Scripting Elements) JSP
HTTP status codes List | Response Status Code Glossary HTTP status codes List | Response Status Code Glossary Important
JSP Directives JSP Directives JSP
Java Server Pages (JSP) Java Server Pages (JSP) JSP

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • JSP Home
  • JSP Scripting Tags
  • JSP Directives
  • JSP Implicit Objects
  • National Farmers Day in Hindi | राष्ट्रीय किसान दिवस पर निबंध | चौधरी चरण सिंह जयंती
  • Human rights day in Hindi: 10 दिसंबर ह्यूमन राइट्स डे
  • Unicef day is celebrated on December 11 | Speech on unicef day
  • Indian Navy Day: जल सेना दिवस कब और क्यों मनाया जाता है?
  • P V Sindhu Biography in Hindi, Badminton, State, Caste पी. वी. सिंधु जीवन परिचय, कहानी, राज्य, जाति
  • Draupadi Murmu Biography In Hindi | द्रौपदी मुर्मू की जीवनी
  • Network kya hai (नेटवर्क क्या है)
    Network kya hai (नेटवर्क क्या है) Networking
  • Difference between Internet and Intranet
    Difference between Internet and Intranet Differences
  • OSI Model | 7 Layers of OSI Model in Computer network
    OSI Model | 7 Layers of OSI Model in Computer network, Functions Networking
  • TCP/IP Model, Full Form, Layers and their Functions
    TCP/IP Model, Full Form, Layers and their Functions Networking
  • IPv4 Vs IPv6 | Difference between IPv4 and IPv6
    IPv4 Vs IPv6 | Difference between IPv4 and IPv6 Differences
  • Difference between TCP and UDP
    Difference between TCP and UDP | TCP vs UDP examples Differences
  • Similarities and difference between OSI and TCP/IP model
    OSI vs TCP/IP Model, Similarities and difference between OSI and TCP/IP model Networking
  • Java Tutorial
  • Servlet Tutorial
  • JSP Tutorial
  • Maven Tutorial
  • HTML Tutorial
  • Programs
  • Hindi/English Grammar
  • Difference Between ... and ...
  • HR Interview
  • Important Articles

Write to Us:
geekcer.code@gmail.com

  • About Us
  • Privacy and Policy
  • Disclaimer
  • Contact Us
  • Sitemap

Copyright © GeekCer 2022 All Rights reserved