tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: URL For Calling Servlet/JSP In Different Context
Date Wed, 25 Jun 2003 15:23:54 GMT

Assuming servlet1 is in context1, accessible as
And servlet2 is in context2, accessible as
you can do:

ServletContext context1 = getServletContext();
ServletContext context2 = context1.getContext("/context2");

if(context2 != null) {
  RequestDispatcher rd2 = context2.getRequestDispatcher("/servlet2");

Then you can forward to servlet2 or include its output in your response.

This requires you to know the name of the 2nd context.  It's also not
that pretty in general, as webapps are supposed to be self-contained.
Why don't you put both servlets in the same context?

Yoav Shapira
Millennium ChemInformatics

>-----Original Message-----
>From: Michael Duffy []
>Sent: Wednesday, June 25, 2003 11:03 AM
>Subject: URL For Calling Servlet/JSP In Different Context
>I've got a servlet in one context that I'd like to
>refer to from another.
>Is it possible to specify a URL across contexts
>without hard-wiring in the host name?  Thanks - MOD
>Do you Yahoo!?
>SBC Yahoo! DSL - Now only $29.95 per month!
>To unsubscribe, e-mail:
>For additional commands, e-mail:

This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message