Multiple Identical Servlets

C

Craig Taylor

I'm wanting to place my servlet in multiple locations under the
webapps folder so that I can be servicing more than 1 source of a
caller (each copy of the servlet will have unique configuration
parameters (config.xml file)).

Do most servlet engines support me "cp -R source newSource" and then
restarting Tomcat to pick up the newSource instance?

Will it truly be a unique instance or because of the servletUid will
it see it as the same?

Thanks,

- Craig Taylor
 
R

Robert Klemme

I'm wanting to place my servlet in multiple locations under the
webapps folder so that I can be servicing more than 1 source of a
caller (each copy of the servlet will have unique configuration
parameters (config.xml file)).

Do most servlet engines support me "cp -R source newSource" and then
restarting Tomcat to pick up the newSource instance?

Will it truly be a unique instance or because of the servletUid will
it see it as the same?

It seems your approach is a bit awkward because by copying code around.
It may not even work because the class file contains the package name.

IMHO a superior approach would be to map the servlet to multiple paths
in web.xml and make the servlet pick a config file based on the path.

Kind regards

robert
 
C

Craig Taylor

It seems your approach is a bit awkward because by copying code around.
It may not even work because the class file contains the package name.

IMHO a superior approach would be to map the servlet to multiple paths
in web.xml and make the servlet pick a config file based on the path.

Kind regards

robert

That would necessitate having the config file be re-read each time the
request was made.

Thinking on it more, I'm thinking now wrapping the servlet into a
management servlet whose sole purpose would be to evaluate the pathing
and invoke the proper (now class, previous servlet) instance.

I'm reasonably certain this situation has popped up before; just
wondering what the proper solution is.

Thanks,

- Craig Taylor
 
K

Kai Schwebke

IMHO a superior approach would be to map the servlet to multiple paths
That would necessitate having the config file be re-read each time the
request was made.

A servlet is created only once and persists between requests, so the
config file is read on the first request only.

Thinking on it more, I'm thinking now wrapping the servlet into a
management servlet whose sole purpose would be to evaluate the pathing
and invoke the proper (now class, previous servlet) instance.

This solution is well known as "Front Controller Pattern":

http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html



Kai
 
M

Mark Jeffcoat

Craig Taylor said:
I'm wanting to place my servlet in multiple locations under the
webapps folder so that I can be servicing more than 1 source of a
caller (each copy of the servlet will have unique configuration
parameters (config.xml file)).

You've gotten more elegant solutions, but ..
Do most servlet engines support me "cp -R source newSource" and then
restarting Tomcat to pick up the newSource instance?

Tomcat won't have any trouble with this; you won't even
have to restart it. Just make the copy, and tell the manager
that you'd like to start the new servlet.

Will it truly be a unique instance or because of the servletUid will
it see it as the same?

I've never specified a servlet id; I had to look it up in the
(web.xml) DTD, which seems to say that you only need it as a
reference for "non-standard information". Are you sure you
even need it?
 
R

Robert Klemme

That would necessitate having the config file be re-read each time the
request was made.

No, that completely depends on your code. You could load config files
on demand and store extracted data in the session / application context
or even internally - whatever is most appropriate for your app. You can
even check whether the config file has changed on disk and reread etc.
Thinking on it more, I'm thinking now wrapping the servlet into a
management servlet whose sole purpose would be to evaluate the pathing
and invoke the proper (now class, previous servlet) instance.
"class"?

I'm reasonably certain this situation has popped up before; just
wondering what the proper solution is.

I am still unsure about what exactly you mean by "this situation".
Maybe you post a bit more explanation on what the application is
supposed to do and what information is stored in those config files.

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top