Geeks Talk

Prepare for your Next Interview




Servlet context and Servlet config

This is a discussion on Servlet context and Servlet config within the Java forums, part of the Software Development category; What is the difference between servlet context and servlet config...


Go Back   Geeks Talk > Software Development > Java

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-13-2008
Junior Member
 
Join Date: Jan 2008
Location: banglore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
narenderreddy is on a distinguished road
Servlet context and Servlet config

What is the difference between servlet context and servlet config
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-14-2008
Junior Member
 
Join Date: Jan 2008
Location: Hyd
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Ramya Ravula is on a distinguished road
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
Reply With Quote
  #3 (permalink)  
Old 06-11-2008
Junior Member
 
Join Date: Apr 2008
Location: NJ,USA
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
asingathi is on a distinguished road
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.
Reply With Quote
  #4 (permalink)  
Old 06-20-2008
Junior Member
 
Join Date: Jan 2008
Location: India
Posts: 19
Thanks: 0
Thanked 3 Times in 1 Post
kumarprabu is on a distinguished road
Re: Servlet context and Servlet config

Sun - what is the difference between servlet config and servlet context?
Reply With Quote
  #5 (permalink)  
Old 06-26-2008
Junior Member
 
Join Date: Jun 2008
Location: INDIA
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
prabhanjanbabub is on a distinguished road
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
Reply With Quote
Reply

  Geeks Talk > Software Development > Java


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
servlet - struts psuresh1982 Java 4 08-22-2008 07:13 AM
when servlet get destroyed ? palempally Java 3 10-24-2007 01:30 AM
servlet nitin.pathak05 Java 1 10-24-2007 12:11 AM
Servlet.xml venu.katta Java 1 10-22-2007 07:42 AM
How many Action Servlet will be available Geek_Guest Java 0 07-01-2007 04:08 PM


All times are GMT -4. The time now is 08:08 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved