» » ServletContext


  • We can deploy multiple web applications in a servlet container.
  • Each web application contains its own resources in a separate  environment. This environment called ad Web Application context or ServletContext.
  • The resources belongs to the one web application context are not available to the other web application context.
  • A Servlet context contains zero or more number of servlets. For every servlet object the container creates separate servletConfig object.
  • ServletContext is an interface. this interface implemented by the container by the container provider.
  • The implemented class allows all servlets in the web application to communicate with the container.
  • We can store common data into this application and also we can share that data even after request response objects deletion in the memory.

ServletContext

 Configure Context parameters in web.xml file

ServletContext


Methods of ServletContext interface:

  1. public String getInitParameter(String name): Returns a String containing a value of the method context-wide initialization  parameter, or null if if parameter does not exist.
  2. public Enumeration getInitParameterNames():Returns the names of the context's initialization parameters as enumeration of string objects , or empty enumeration if context has no initialization parameters.
  3. public void setAttribute(String name,Object object):sets the given object in the application scope.
  4. public Object getAttribute(String name):Returns the servlet container attribute with the given name , or null if there is no attribute by that name.
  5. public Enumeration getInitParameterNames():Returns the names of the context's initialization parameters as an Enumeration of String objects.
  6. public void removeAttribute(String name):Removes the attribute with the given name from the servlet context.
  7. public int getMajorVersion(): Returns the major version of the Java Servlet API that is servlet container supports.
  8. public int getMinorVersion(): Returns the minor version of the Java Servlet API that is servlet container supports.
  9. public void log(Java.lang.String msg): Writes specified message to a servlet log file, usually an event log.

How to get the object of ServletContext interface:

       ServletContext application=getServletConfig().getServletContext();   
          String driverName=application.getInitParameter("name");  


Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu