tomcat-users mailing list archives

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

Howdy,
Assuming servlet1 is in context1, accessible as
http://yourhost:yourport/context1/servlet1,
And servlet2 is in context2, accessible as
http://yourhost:yourport/context2/servlet2,
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 [mailto:duffymo@yahoo.com]
>Sent: Wednesday, June 25, 2003 11:03 AM
>To: tomcat-user@jakarta.apache.org
>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!
>http://sbc.yahoo.com
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message