servlet

Discussion in 'Java' started by Ayrton, Aug 5, 2005.

  1. Ayrton

    Ayrton Guest

    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

    --
    Questa รจ una firma automatica di MesNews.
    Sito: http://www.mesnews.net
     
    Ayrton, Aug 5, 2005
    #1
    1. Advertising

  2. Hi,

    Ayrton wrote:
    > 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
     
    Ingo R. Homann, Aug 5, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    4
    Views:
    2,423
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,903
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    2,021
    Jack Jia
    Apr 4, 2004
  4. chamikara
    Replies:
    1
    Views:
    49,880
  5. DiscoStu
    Replies:
    0
    Views:
    506
    DiscoStu
    Jul 8, 2004
Loading...

Share This Page