VOOZH about

URL: https://www.geeksforgeeks.org/java/jsp-application-implicit-objects/

⇱ JSP Application - Implicit Objects - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

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

Step 2: Configure web.xml

  • Define servlet mapping
  • Add context parameter

web.xml file

Step 3: Create welcome.jsp

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

welcome.jsp

Output:

  • Displays user name entered
  • Displays application-level parameter
👁 Image
👁 Image

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
Article Tags:
Article Tags: