• Post Reply Bookmark Topic Watch Topic
  • New Topic

Diff between ServletConfig and ServletContext

 
hhabib rahman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,
can anyone explain me the difference between ServletConfig and ServletContext.
what are the uses of both objects.
 
krishnamoorthy kitcha
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!