Subject: Can a server call an other servlet?
> Hello!
>
> Let's say I have some servlet, and each of them would like to reach a
> function I write into one of them. Can the others reach it somehow? Maybe
> if I restructure the code?
Easiest way - write a base Servlet class containing the definition of the
method you want
to reuse. Each Servlet that wants to have this method can then extend the
base Servlet:
the base Servlet will be the superclass for a whole bunch of Servlets that
are customised to
a more specific task.
You can even call the base Servlet something like 'BasePlokServlet' - and
make it abstract
to enforce the design decision.
> I don't want to package this function to an outstanding (not tomcat -
> jakarta servlet) file.
Why? If the method(s) needed by a bunch of Servlets are in some Helper
Class, an instance of which can be a
private member in a BaseServlet, it cannot possibly do any harm - unless the
methods are not thread safe.
Miles