This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing one servlet from another

 
Harri Elef
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i am trying to call one servlet from another servlet. The two servlet belong to different applications but deployed on the same tomcat.

Can someone tell me what is the best way to do that?


Thanks a lot

Harri Elef
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext.getContext(String uripath) can get a reference to another servlet context, and from there you can access resources in that context such as Servlets. There are a few things to keep in mind:

1) Depending on the container, you will need to look at the documentation to see if you need configuration settings to allow this. By default it is not allowed.
2) Communication with the other Servlet may be via another Thread, so the the data may not arrive as you expect.
3) cross context communication is typically poorly implemented in containers, and is poorly defined in the spec.
[ February 04, 2008: Message edited by: David O'Meara ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic