Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling Servlets in different Web applications?

 
Karthi Bala
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can I call a method in a servlet which is instantiated in a web application from another servlet which is in different web application.
I don't want the instantiate the servlet again?
Thanks
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't recommend it. You can get into all sorts of trouble - the servlets may someday end up in separate VMs, so it would be physically impossible. Even if not, this is a dangerous way to organize things, as you're creating non-obvious dependencies both on data and on thread processes.
It would be safer if you could extract the common functionality into a component in its own right. For simple cases, this might just be a library class. If there's more complexity or shared data, I'd recommend looking at Enterprise JavaBeans.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic