Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

servletcontext and servletconfig  RSS feed

 
anita dhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between servletcontext and servletconfig
in which situations we are using these
any practical example
[ June 07, 2007: Message edited by: David O'Meara ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please dont write all in capitals, as it is considered "shouting" and is not very nice.

thanks,
Dave
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They're different objects with different purposes.

The best place to go for answers to "difference between" questions like this is the the API.

You can find a link to the J2EE API in my signature.
[ June 07, 2007: Message edited by: Ben Souther ]
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use ServletContext when you want information that should span across your entire web app. You use ServletConfig when you want information that should span your specific servlets. The HFSJ explains this clearly!
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletConfig is specific to a given servlet mapping.

For example, you could have one TaxPortlet, but create 52 mappings, one for each state, in the web.xml file. For each state, you put a ServletConfig mapping for the state tax rate. As a result, each servlet mapping is unique - the TaxPortlet mapping for Nevada has a different state tax rate than the one for Florida.

On the other hand, ServletContext is common to all Servlets in a given war, so while each ServletMapping, for each state perhaps, would have a unique value for the state tax rate, EVERY Servlet in the war would share a common federal tax rate.

Hope that didn't make it more confusing.

-Cameron
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Cameron W. McKenzie:
ServletConfig is specific to a given servlet mapping.

For example, you could have one TaxPortlet, but create 52 mappings, one for each state, in the web.xml file. For each state, you put a ServletConfig mapping for the state tax rate. As a result, each servlet mapping is unique - the TaxPortlet mapping for Nevada has a different state tax rate than the one for Florida.

On the other hand, ServletContext is common to all Servlets in a given war, so while each ServletMapping, for each state perhaps, would have a unique value for the state tax rate, EVERY Servlet in the war would share a common federal tax rate.

Hope that didn't make it more confusing.

-Cameron


Correction:
The config object is specific to each servlet entry.
Init params don't go in the mapping entries.
They go in the servlet entries.

You can do what you've described by having multiple servlet entries, all using the same servlet class, each having it's own servlet meapping.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!