• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

servletcontext and servletconfig

 
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 ]
 
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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • 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 ]
 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE 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!
 
author and cow tipper
Posts: 5000
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 VI Editor Redhat
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic