Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Multiple Identical Servlets

Thread view: 
Craig Taylor - 15 Mar 2007 16:50 GMT
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
Robert Klemme - 15 Mar 2007 17:02 GMT
> 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
[quoted text clipped - 6 lines]
> 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
Craig Taylor - 15 Mar 2007 18:52 GMT
> > 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
[quoted text clipped - 16 lines]
>
>         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
Kai Schwebke - 15 Mar 2007 19:14 GMT
>> 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.

> 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
Lew - 16 Mar 2007 04:08 GMT
Craig Taylor wrote:
>> 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

For an implementation:
<http://struts.apache.org/>

-- Lew
Robert Klemme - 16 Mar 2007 14:15 GMT
>>> 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
[quoted text clipped - 16 lines]
> 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
Mark Jeffcoat - 15 Mar 2007 21:12 GMT
> 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?

Signature

Mark Jeffcoat
Austin, TX



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.