Results 1 to 5 of 5

Thread: Servlet context and Servlet config

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Answers
    1

    Servlet context and Servlet config

    What is the difference between servlet context and servlet config


  2. #2
    Junior Member
    Join Date
    Jan 2008
    Answers
    1

    Smile Re: Servlet context and Servlet config

    Servlet Config is a private area for every servlet(variable declared here are accessible only 2 that particular servlet)

    While Sevlet Context is a shared area for every servlet in
    an applicationi.e., all the servlet's in this application can access this variables in servlet context,an best example for this is,we can keep variables like database connection objects


  3. #3
    Junior Member
    Join Date
    Apr 2008
    Answers
    5

    Re: Servlet context and Servlet config

    Servlet Config : is used to initialize any configuration value for a particular servlet engine.
    generally we will configure it in the web.xml using <init-param> . we will retrieve these values in the init() method of the Servlet. For example : we can initialize the DB properties here i.e. driver name, driver url, db user and password.

    Servlet Context : it is used to store the java objects. these are accessed anywhere with in the Servlet Container.


  4. #4

  5. #5

    Re: Servlet context and Servlet config

    For every web applicaion there is one and only servletContext object. For every servlet there is a servletConfig object. All the servlets in a web application will share the data through servletContext. servletConfig is used to initialize the servlet variabes. servletContext is one of the scopes(session,request,servletContext) of the servlet to share data with other servlets.

    ---------web.xml-----------
    <servlet>
    <servlet-name></servlet-name>
    <servlet-class>Servlet1</servlet-class>
    <init-param>
    <param-name>servletconfig</param-name>
    <param-value>servletconfig</param-value>
    </init-param>
    <servlet>
    <context-param>
    <param-name>servletcontext</param-name>
    <param-value>servletcontext</param-value>
    </context-param>
    -------------------------------------------------------------------
    getInitParameter("servletcofig");//only for Servlet1
    getServletConfig().getServletContext().getInitParameter("servletcontext");//can be accessed at any srvlet


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact