• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Diff between ServletConfig and ServletContext

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all,
can anyone explain me the difference between ServletConfig and ServletContext.
what are the uses of both objects.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rahman

Check this one for your reference

servlet context is used if you want some values which must exist for the life time of the application. A servlet config object used by a servlet container to pass information to a servlet during initialization.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.


1)
Parameters defined in the ServletContext are visible for all servlets

Where as parameters defined in the ServletConfig are visible to the servlet where it has been defined .


2)

ServletContext has application scope wide
where as ServletConfig has Servlet scope

ServletContext has a life time as that of container.,


Only one time we can modify the servlet information by ServletConfig while Servlet(Server) loaded or initiated. But by ServletContext we can modify the information when we need at any tme in the whole application of the program.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Other than both starting with "ServletCon" the two are not really comparable.

Anytime you're unsure about a method in the servlet API, the best place to go is the Javadoc for that API:

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletConfig.html
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic