The Application Object in JSP

By: Sathya Narayana Emailed: 1584 times Printed: 2041 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

The application object is an instance of a class that implements the javax.servlet.ServletContext interface, and it allows the page to obtain and to set data information about the Web application in which it's running. It makes available the following methods.

getAttribute() returns the value of the specified attribute name. The return value is an Object or subclass if the attribute is available to the invoking ServletContext object or null if the attribute isn't available:

public Object getAttribute(String name)

getAttributeNames() returns an Enumeration containing the attribute names available to the invoking ServletContext object:

public java.util.Enumeration getAttributeNames()

getContext() returns the ServletContext object for the resource at the specified path on the server. The path argument is an absolute URL beginning with /:

public ServletContext getContext(String uripath)

getInitParameter() returns a String object containing the value of the specified initialization parameter or null if the parameter doesn't exist:

public String getInitParameter(String name)

getInitParameterNames() returns a Enumeration containing the initialization parameters associated with the invoking ServletContext object:

public java.util.Enumeration getInitParameterNames()

getMajorVersion() returns the major version of the Java servlet API that the server supports. For servers supporting version 2.3 of the servlet specification, this method will return 2:

public int getMajorVersion()

getMimeType() returns the MIME type of the specified file or null if the MIME type can't be ascertained. Typical return values will be "text/plain", "text/html", and "image/jpg":

public String getMimeType(String file)


getMinorVersion() returns the minor version of the Java servlet API that the server supports. For servers supporting version 2.3 of the servlet specification, this method will return 3:

public int getMinorVersion()

getNamedDispatcher() returns a RequestDispatcher object that will be wrapped around the named servlet:

public RequestDispatcher getNamedDispatcher(String name)

getRealPath() returns a String object containing the real path, in a form appropriate to the platform on which the servlet is running, corresponding to the given virtual path. An example of a virtual path might be "/blah.html":

public String getRealPath(String path)

getRequestDispatcher() returns a RequestDispatcher object that acts as a wrapper around the resource located at the specified path. The path must begin with / and is interpreted relative to the current context root:

public RequestDispatcher getRequestDispatcher(String path)

getResource() returns a URL object that's mapped to the specified path or null if there's no resource mapped to the path. The path must begin with / and is interpreted relative to the current context root:

public java.net.URL getResource(String path)
throws java.net.MalformedURLException

getResourceAsStream() returns the resource at the specified path as an InputStream object:

public java.io.InputStream getResourceAsStream(String path)

getResourcePaths() returns all the paths to resources held in the Web application as String objects beginning with a /:

public java.util.Set getResourcePaths()

getServerInfo() returns a String object containing information about the server on which the servlet is running. At a minimum, the String will contain the servlet container name and version number:

public String getServerInfo()

The following will display Apache Tomcat/5.0.16 for Tomcat 5.0.16:

<% out.print(application.getServerInfo()); %>

getServletContextName() returns the name of the Web application, as specified in the <display-name> element in web.xml:

public String getServletContextName()

log() is used to write a message to the servlet engine's log file. The second version writes both an explanatory message and a stack trace for the specified Throwable exception to the log file:

public void log(String msg)
public void log(String message,
Throwable throwable)

removeAttribute() makes the specified attribute unavailable to the invoking ServletContext object. Subsequent calls to the getAttribute() method for this attribute will return null:

public void removeAttribute(String name)

setAttribute() binds a value to a specified attribute name:

public void setAttribute(String name,
Object object)

These methods are deprecated and shouldn't be used in new code—they exist for compatibility with existing code:

public Servlet getServlet(String name)
throws ServletException
public java.util.Enumeration getServletNames()
public java.util.Enumeration getServlets()

public void log(Exception exception,
String msg)



JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sathya Narayana
Querying Data with the JSTL in JSP
Deleting Data in MySQL
Modifying data and using WHERE clause in MySQL
Querying the Database in MySQL
Inserting Data into Tables in MySQL
Changing the Structure of an Existing Table in MySQL
The Exception Object in JSP
The Application Object in JSP
The Session Object in JSP
The Out Object in JSP
The Response Object in JSP
The Request Object in JSP
Tag Libraries in JSP
Scriptlets and Expressions in JSP
Declarations in JSP

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Example to connect to MS SQL database and retrieve records
JSP Alert Example
What are the different scopes in JSP?
JSP CheckBox Example
JSP Program for display Date
Sending Email using JSP
Comparison operators in JSP
Arithmetic Evaluation Using the Expression Language in JSP
Enable/Disable Scripting Elements in JSP
Querying Data with the JSTL in JSP
Automatically Refreshing a JSP
Uploading an Image to a Database using JSP
Tags using in jsp
Form processing in JSP
NotifyUtil::java.net.ConnectException: Connection refused: connect
Most Emailed Articles (in JSP)
Click to Activate and Use this control
Embedding java codes in jsp sciptlets
HttpClient
NotifyUtil::java.net.ConnectException: Connection refused: connect
Comparison operators in JSP
Document Object
Form processing in JSP
JSP Program for display Date
The Servlet Life Cycle
Enable/Disable Scripting Elements in JSP
Steps to get a Free SSL certificate for your Tomcat
Cookies using JSP or Java Bean
The JSP Program running first Time.
JSP pages in servlet
JSP Directives