• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many ServletContext's can exist in a web application?

 
Krishna, Alle
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
1) There can only be a single ServletContext for a web application and only one. This is true.
2) But when in a distributable web application, which spans across multpile JVMs, it can have again one and only one ServletContext.
3) Hanumant's book says, there can exist different ServletContexts on different machines.
Can someone please clarify if I have misunderstood the concept of ServletContext because I feel statements 2 and 3 above appear to contradict each other.
Thank you folks in advance.
Vasanth
 
Mark Stein
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a web app is distributed among different machines (multiple JVM's), each JVM has it's own copy of the application on it, therefore it has it's own appname/WEB-INF/web.xml
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the servlet specification, there is one instance object of the ServletContext interface associated with each web application deployed into a container. A web application will have an instance of the ServletContext for eacth Virtual Machine, in cases where the container is distributed over many virtual machines
daniel
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,the way I see it:
The default context has only ONE instance while all non default contexts have a instance on each JVM in a distributed environment.
 
Rama Raghavan
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a line from the interface definition of the javadoc for ServletContext
There is one context per "web application" per Java Virtual Machine.
Also - In the case of a distributed application(app deployed in a cluster), there will be one context instance for each virtual machine.
I disagree about a single instace of "default" context. I think there will be one servlet context per JVM, default or otherwise.
Rama
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic