<div dir="ltr" style="text-align: left;">
<div dir="ltr" style="text-align: left;">
<p>The application implicit object is an instance of <b><i>javax.servlet.ServletContext</i></b>. It is the broadest context state available. It allows the JSP page&#8217;s servlet and any Web components contained in the same application to share information. A typical use of the application object is to get access to the application wide initialization parameters. The following two scriptlets are equivalent:</p>
<pre class="highlight"><;% String path = application.getRealPath ("/WEB-INF/doj.txt"); %>; 
<;% String path = getServletContext ().getRealPath ("/WEB-INF/doj.txt"); %>; 
</pre>
<h2><b>Methods of implicit object <i>application</i>:</b><br />
<i><b></b></i></h2>
<h3><i><b>getAttribute(String name) : </b></i></h3>
<p>This method returns the &#8216;object&#8217; stored in specified attribute name. If the specified parameter does not exist , it will return &#8216;null&#8217; value.</p>
<p><b>Example :</b></p>
<pre class="highlight">application.getAttribute("doj"); 
</pre>
<h3><b><i>getAttributeNames() : </i></b></h3>
<p>This method returns all the attributes available within the application. The return type is Enumeration.</p>
<p><b>Example :</b></p>
<pre class="highlight">Enumeration doj; 
 doj= application.getAttributeNames(); 
</pre>
<h3><i><b>setAttribute(String objName, Object object) :</b></i></h3>
<p>This method stores the &#8216;object&#8217; in the object name provided(String objname) in the application.</p>
<p><b>Example : </b></p>
<pre class="highlight">application.setAttribute("varName", varValue); 
</pre>
<h3><i><b>removeAttribute(String objName) : </b></i></h3>
<p>This method is used to remove the specified attribute (String objName) from the application.</p>
<p><b>Example : </b></p>
<pre class="highlight">application.setAttribute("password",password); 
 application.removeAttribute("password"); 
</pre>
<h3><b><i>getMajorVersion() : </i></b></h3>
<p>This method is used to return the major version of the Servlet API for the JSP Container.</p>
<p><b>Example :</b></p>
<pre class="highlight">out.println("Major Version:"+application.getMajorVersion()); 
</pre>
<p><b>Output : </b> Major Version:2</p>
<p>The above statement gives 2 as the major version of the Servlet API in use for the Application object.</p>
<h3><i><b>getMinorVersion() : </b></i></h3>
<p>This method is used to return the minor version of the Servlet API for the JSP Container.</p>
<p><b>Example : </b></p>
<pre class="highlight">out.println("Minor Version: "+application.getMinorVersion()); 
</pre>
<p><b>Output : </b>Minor Version: 1</p>
<p>The above statement gives 1 as the minor version of the Servlet API in use for the Application object.<br />
<b><i></i></b></p>
<h3><b><i>getServerInfo(): </i></b></h3>
<p>The method &#8216;<i><b>getServerInfo</b></i>&#8216; of Application object is used to return the name and version number of the JRun servlet engine. Information about the JSP Container, such as, the name and product version, are returned by the method <i><b>getServerInfo </b></i>of Application object.</p>
<p><b>Example : </b></p>
<pre class="highlight">out.println("Server Information:"+application.getServerInfo()); 
</pre>
<h3><i><b>getInitParameter(String name):</b></i></h3>
<p>The method &#8216;<b><i>getInitParameter</i></b>&#8216; of Application object is used to return the value of an initialization parameter. If the parameter does not exist, then null value is returned.</p>
<p><b>Example :</b></p>
<pre class="highlight">String doj = application.getInitParameter("eURL"); 
</pre>
<p>In the above example, the value of initialization parameter &#8220;eURL&#8221; is retrieved and stored in string &#8220;doj&#8221;.</p>
<h3><i><b>getInitParameterNames() : </b></i></h3>
<p>The method &#8216;<b><i>getInitParameterNames</i></b>&#8216; of Application object is used to return the name of all initialization parameter of the application. The returned value is an enumeration.</p>
<p><b>Example : </b></p>
<pre class="highlight">Enumeration e; 
 e=application.getInitParameterNames(); 
</pre>
<h3><i><b>getResourceAsStream(Path): </b></i></h3>
<p>The method &#8216;<i><b>getResourceAsStream</b></i>&#8216; of Application object is used to translate the resource URL mentioned as parameter in the method , into an input stream to read.<br />
<b>Example :</b></p>
<pre class="highlight">InputStream stream = application.getResourceAsStream("/doj.txt") 
</pre>
<h3><i><b>log(Message) :</b></i></h3>
<p>The method log of Application object is used to write a text string to the JSP Container?s default log file. General syntax of log method of Application object is as follows :</p>
<pre class="highlight">application.log(Message); 
</pre>
<h2><b>JSP <i>application </i>Object Example:</b><br />
<b><br />
</b> <b>First JSP:</b></h2>
<pre class="highlight"><;%@ 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>; 
<;title>;JSP Application Object Example<;/title>; 
<;/head>; 
<;body>; 
 <;% 
 application.setAttribute("name", "Dinesh"); 
 %>; 
 <;a href="test.jsp?id=5">;JSP Application Example<;/a>; 
<;/body>; 
<;/html>; 
</pre>
<p><b>Second JSP:<br />
test.jsp</b></p>
<pre class="highlight"><;%@ 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>; 
<;title>;JSP Application Object Example<;/title>; 
<;/head>; 
<;body>; 
 Application attribute value: <;%=application.getAttribute("name")%>; 
<;/body>; 
<;/html>; 
</pre>
</div>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/jsp-session-object/">Previous</a> <;<; || <a href="https://dineshonjava.com/jsp-tutorial-baby-step-to-server-pages/">Index </a>|| >;>;<a href="https://dineshonjava.com/exception-implicit-object/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/jsp-session-object/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/exception-implicit-object/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '330'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…