• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Forwarding request to servlet outside the webapp

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far i know you can use sendRedirect with RequestDispatcher to access a servlet residing outside the current webapp.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic