JSP Application - Implicit Objects

Last Updated : 16 May, 2026

In JSP, the application is an implicit object of type ServletContext. It is created once by the web container when the web application is deployed and is shared across all JSP pages. It is mainly used to store and retrieve data that is accessible throughout the entire application.

  • Available to all JSP pages (application scope)
  • Helps access initialization parameters from web.xml
  • Used to share data globally across users

Common Methods of Application Object

  • setAttribute(String, Object): Stores data in application scope
  • getAttribute(String): Retrieves stored data
  • removeAttribute(String): Removes stored attribute
  • getAttributeNames(): Returns all attribute names
  • getInitParameter(String): Retrieves initialization parameter from web.xml
  • getInitParameterNames(): Returns all initialization parameters
  • getRealPath(String): Converts virtual path to actual system path
  • log(String): Writes message to server log
  • getServerInfo(): Returns server information

Step-by-Step Implementation of JSP Application

This section explains the process of creating and configuring JSP files to use the application implicit object for sharing data across the entire application.

Step 1: Create index.html

  • Create an HTML form to take user input
  • On submit, data is sent to welcome.jsp

index.html file 

HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<form action="welcome">
<input type="text" name="uname">
<input type="submit" value="go"><br/>
</form>

</body>
</html>

Step 2: Configure web.xml

  • Define servlet mapping
  • Add context parameter

web.xml file

XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
  <display-name>HelloWorld</display-name>
  
  <servlet>
  <servlet-name>welcome</servlet-name>
  <jsp-file>/welcome.jsp</jsp-file>

  </servlet>
  
  <servlet-mapping>
  <servlet-name>welcome</servlet-name>
  <url-pattern>/welcome</url-pattern>
  </servlet-mapping>
  
  <context-param>
  <param-name>dname</param-name>
  <param-value>com.mysql.jdbc.Driver</param-value>
  </context-param>
  
</web-app>

Step 3: Create welcome.jsp

  • Retrieve user input using request.getParameter()
  • Access application data using application.getInitParameter()
  • Display both values

welcome.jsp 

HTML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>GeeksforGeeks</title>
</head>
<body>

<%
out.print("Welcome "+request.getParameter("uname"));
String driver=application.getInitParameter("dname");
out.print("<br/>driver name is="+driver);  
%>

</body>
</html>

Output:

  • Displays user name entered
  • Displays application-level parameter

Explanation:

  • User enters name in index.html
  • Request goes to welcome.jsp
  • JSP displays user name
  • Application object retrieves global parameter (driver name)
  • Output shows both user input and application-level data

Advantages

  • Data shared across entire application
  • Reduces duplication of configuration data
  • Useful for global settings
Comment