• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forwarding request to servlet outside the webapp

 
praveen sainath
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anybody tell if we can forward a request using RequestDispatcher, to a servlet residing outside the current webapp.
One of my friends told
ServletContext context = ContextStorage.getContext("/contextUrl");

will get the context of web app specified by the "/contextUrl".

Is this the method to get the other context and forward the request to a jsp or servlet in that context.
Please make it clear to me.
 
Vinod Iyer
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far i know you can use sendRedirect with RequestDispatcher to access a servlet residing outside the current webapp.
 
Hunny Lee
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by praveen sainath:

...

...


I do not know any ContextStorage in the servlet API. I'm interested, where did your friend get that?

You cannot use request.getRequestDispatcher to access a URL outside of the current servlet context.

You may use response.sendRedirect(url) to redirect to any page you like, if you don't mind that you lose your current request data.
 
praveen sainath
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I will surely ask my friend and tell you from where did he get the ContextStorage class
So, the conclusion is we cannot pass the request object to any servlet or jsp that is in another context.
Please correct me if I am wrong.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the server you use. In Tomcat this can be enabled on a Context-by-Context basis using the crossContext attribute. See http://tomcat.apache.org/tomcat-5.5-doc/config/context.html for details.
 
Tridib Samanta
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can retrieve(ie. server allows) the ServletContext for any web apps, you can use RequestDispatcher to forward the request.

Here is what mentioned in API
This method(ie. ServletContext.getContext()) allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container.

In a security conscious environment, the servlet container may return null for a given URL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic