wood burning stoves 2.0*
The moose likes Servlets and the fly likes 2 Servlet Contexts in Single Appication? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "2 Servlet Contexts in Single Appication?" Watch "2 Servlet Contexts in Single Appication?" New topic
Author

2 Servlet Contexts in Single Appication?

Rajendra
Ranch Hand

Joined: Feb 21, 2006
Posts: 48
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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


[My Blog]
All roads lead to JavaRanch
Rajendra
Ranch Hand

Joined: Feb 21, 2006
Posts: 48
If we set context parameters to each specific servlet ,
then what is meant by Servlet Context per application???
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
Marshal

Joined: Mar 22, 2005
Posts: 41087
    
  43
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).


Ping & DNS - my free Android networking tools app
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
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

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Feb 05, 2003
Posts: 4727

Crosspost was made to SCWCD. I'm closing the one in SCWCD but keeping it displayable because of the good answer shared there.


A good workman is known by his tools.
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
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.
 
Consider Paul's rocket mass heater.
 
subject: 2 Servlet Contexts in Single Appication?
 
Similar Threads
2 Servlet Contexts in Single Appication?
ServletContext question.
HTTPSession scope, multiple WAR's, multiple EAR's
Static Properties in Classes used by Servlets
about instance of servlet