This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Accessing one servlet from another Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Accessing one servlet from another" Watch "Accessing one servlet from another" New topic

Accessing one servlet from another

Harri Elef

Joined: Feb 04, 2008
Posts: 2

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

Joined: Mar 06, 2001
Posts: 13459

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 ]
I agree. Here's the link:
subject: Accessing one servlet from another
Similar Threads
Servlet Chaining
Invoking methods present in jsp/servlet from another jsp/servlet
Sevlet Request Dispatcher
In how many ways we can call another servlet from the doPOST()
Forwarding a request to another servlet in a different WEB-APP