Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 Servlet Contexts in Single Appication?

 
Rajendra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

1) Is it possible to put 2 servlet contexts in a single application? If yes how can we use those?

2) Can we use same Servlet class for different servlets in a application?

( Same class can be used for different URL's???)

Thanks,
Rajendra.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) You can set a context parameters for each servlet in an application (one per servlet)

2) Yes. Different mappings pointing to the same servlet
 
Rajendra
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If we set context parameters to each specific servlet ,
then what is meant by Servlet Context per application???
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API:

There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace such as /catalog and possibly installed via a .war file.)

In the case of a web application marked "distributed" in its deployment descriptor, there will be one context instance for each virtual machine. In this situation, the context cannot be used as a location to share global information (because the information won't be truly global). Use an external resource like a database instead.

The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rajendra-

On your way in you missed that JavaRanch has a policy on display names, and yours does not comply with it; specifically, a first name and a last name are required. Please adjust it accordingly, which you can do right here. Thanks for your prompt attention to this matter.

As to your question, what you can set per servlet is, I believe, called servlet parameter, not context parameter. So you can have different servlet parameters for the same servlet class in a web app, but there is only a single context (and its parameters are the same for all servlets).
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to put 2 servlet contexts in a single application? If yes how can we use those?


Is this not the same as creating two different applications and putting them in the same EAR.

What do you want to achieve by sharing a context, with two applications?
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by geetu lalchandani:


What do you want to achieve by sharing a context, with two applications?


Geetu, he is asking just reverse, one application and two context... not two application and one context...
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crosspost was made to SCWCD. I'm closing the one in SCWCD but keeping it displayable because of the good answer shared there.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geetu, he is asking just reverse, one application and two context... not two application and one context...


rathi ji, I meant the same thing. You have two applications, with two different contexts, now when you put them in a single EAR, then, it will be a single application.

Though i tried getting the context parameters, from the applications and you wouldnt get them for both, that means, i couldnt share the contexts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic