servlet

A

Ayrton

In my project I've 2 servlet and I wuold like use a method of first
servlet ( that is in use from the web ) in second sevlet, is possible ?
I need to access of istance of it, but not create a new istance.

Thanks
 
I

Ingo R. Homann

Hi,
In my project I've 2 servlet and I wuold like use a method of first
servlet ( that is in use from the web ) in second sevlet, is possible ?
I need to access of istance of it, but not create a new istance.

So, your problem is to get an instance of the 2. servlet?

Or can you make the method static?

Try one of the following:

class Servelt1 {
void foo() {
Servlet2.bar();
}
}
class Servlet2 {
static void bar() {...}
}

or perhaps:

class Servelt1 {
void foo() {
Servlet2.instance.bar();
}
}
class Servlet2 {
static Servlet2 instance=new Servlet2();
void bar() {...}
}

Or, move the (static) method bar to another class (perhaps the cleanest
solution).

Ciao,
Ingo
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top