Java Object


How can I get a reference to an object( already instantiated) from different java codes?

Well I am trying to develop a Web application where in the "mainclass -method to access backend", is instantiated once, during server startup.
Now I want to get a reference of it so that I can call any of its method in any Servlet or JSP or a jhtml?

IS RMI the only way, or is there a simpler way?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The only way as far as I know is RMI.

With Servlet API 2.0 it was possible to directly connect to an other servlet. We did this to get this "mainclass" feature. But starting with Servlet API 2.1 this possiblity is not given any longer.
One way to do it may be to use one servlet as "mainclass" an forward any request, which has to be processed by the "mainclass" to this servlet. Then forward the answer to either an servlet or an jsp. But this may be imperformant.

Hope this helps,


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CORBA would be an alternate solution.  I don't think it would be much easier since you will have to deal with things like firewalls.
W122498Author Commented:
I think RMI would be a better alternative to CORBA
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.