Results 1 to 6 of 6

Thread: Differentiation between servletConfig and servletContext

  1. #1
    Join Date
    Dec 2009
    Posts
    32

    Differentiation between servletConfig and servletContext

    Hello Guys,

    I am totally confused between servletConfig and servletContext objects of servlet. Both of these objects seems to be have similar functionality in servlet. I know these objects of servlet is basically used to hold the references. But I am unable to find the differences between servletConfig and servletContext. Does anyone knows about the differentiation between servletConfig and servletContext? if yes then please let me know that.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Differentiation between servletConfig and servletContext

    The purpose ServletConfig is an interface. This interface contains the following four methods:
    1. getServletName():This returns a String containing the name of the instance of the servlet.
    2. getServletContext():This returns a reference to the interface ServletContext.
    3. getInitParameterNames() : This returns an object Enumeration containing the parameters initialization of the servlet.
    4. getInitParameter() : This returns a String which includes the initialization of the servlet parameter .

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Differentiation between servletConfig and servletContext

    Hi friend,

    The interface ServletContext includes methods getMajorVersion () and getMinorVersion () to indicate which version of the Servlet API is used. To access a resource from a servlet, it must pass through the ServletContext interface. For the ServletContext in a servlet (that is to say in a class inherits from HttpServlet), must be this.getServletContext (), which we must returns a ServletContext object reference.

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Differentiation between servletConfig and servletContext

    The ServletContext object has two methods that : The method setAttribute (String attrName, Object attribValue), and the method getAttribute (String attrName). When you want a servlet, set a attribute of the application, that is to say, a global variable to the application, must be this.getServletContext (). To retrieve 'setAttribute ( "myAttribute", myObject)' object in a JSP page, do: myObject = application. setAttribute ( "myAttribute").

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Differentiation between servletConfig and servletContext

    Javax.Servlet.ServletConfig is an interface. The ServletConfig object is an object which is passed to the method Init () to allow the servlet container (i.e the application server, e.g Tomcat) to pass configuration information to the servlet. The Init method of the Servlet interface is a method used to Initialization of the servlet. This method is called once, and just after instantiating the servlet. Initialization is the last step of loading a servlet. A Servlet must be initialized before responding to requests from the client.

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Differentiation between servletConfig and servletContext

    The object type ServletConfig passed as a parameter to method and which enables access to an object of type ServletContext (because it implements the ServletContext interface) that describes the execution environment where the servlet is running. The servers generally have a log file for that, and servlet engines are no exception to the rule. To use these log files, it is recommended to use the method log (String message) or log (Exception e, String message) of the ServletContext interface. The first written message in the log message from the server, the second adds to the message stack trace (the result of e.printStackTrace ()).

Similar Threads

  1. How to call ServletConfig methods in J2EE
    By Assasin boy in forum Software Development
    Replies: 5
    Last Post: 25-07-2010, 03:25 AM
  2. Differentiation between XML and PHP
    By Gokul20 in forum Software Development
    Replies: 5
    Last Post: 10-03-2010, 03:43 PM
  3. Differentiation between XML and Html
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 12:27 PM
  4. Differentiation between servletcontext and pagecontext?
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 08:41 AM
  5. Differentiation between WAN and LAN
    By Dolsy_bendal in forum Networking & Security
    Replies: 4
    Last Post: 30-11-2009, 10:46 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,873,236.57533 seconds with 17 queries