aspose file tools*
The moose likes Servlets and the fly likes Forwarding to a URL outside the container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Forwarding to a URL outside the container" Watch "Forwarding to a URL outside the container" New topic
Author

Forwarding to a URL outside the container

Chet Arora
Greenhorn

Joined: May 20, 2003
Posts: 29
Hi,

I have a requirement where i need to forward a servlet request to outside the container and fill in some attributes into it before i forward it to this site. Iv tried the response.sendRedirect but it doesnt let me go outside the container and RequestDispatcher redirect resets the request information.

Does anybody have a solution for this ?

Regards,

Chetan
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
You can not use request dispatcher for dispatching requests to outside a container , even you cannot dispatch to some other application in the same container.

If you want to use the same request for this and having attributes attached to it , it might be difficult.But in case you do not have any request attribute then you might request the servlet outside the container using normal HTTP request (For requesting you can use HTTPClient or , HTTPURLConnection) and pass parameters using URL/GET method or body/POST method.


Rahul Bhattacharjee
LinkedIn - Blog
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by Rahul Bhattacharjee:
even you cannot dispatch to some other application in the same container.


I think, forward() is possible b/w two different application on same container. Am I wrong?

:roll:
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Originally posted by ankur rathi:
I think, forward() is possible b/w two different application on same container. Am I wrong?


Partly wrong, since it depends on the server being used. E.g., in Tomcat it is possible only if the crossContext attribute of the Context is set. By default it's turned off.

BTW, I don't think the rolling eyes icon conveys what you are trying to convey here: SaloonGraemlins
[ May 25, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Ulf Dittmer:


Partly wrong, since it depends on the server being used. E.g., in Tomcat it is possible only if the crossContext attribute of the Context is set. By default it's turned off.


I do not have any idea about this.But as you have written ,I am sure there surely does exists something like that.

But my question is how can a container vendor do something like this which is not specified in the servlet specification.
This does effect the portability of the application where this application will be restricted to only containers supporting this added feature.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
But my question is how can a container vendor do something like this which is not specified in the servlet specification.


The servlet specification lists features that a container must implement, and concentrates on the "deployment descriptor" (web.xml). Vendors are free to add features.

Tomcat is the "Reference Implementation" of the servlet and jsp APIs.

Bill


Java Resources at www.wbrogden.com
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by William Brogden:
Vendors are free to add features.


Invoker servlets in Tomcat is one such added functionality.

But this reduces the applications portability.

The application then is bound to only Tomcat ,if that uses stuffs like crossContext attribute.
Chet Arora
Greenhorn

Joined: May 20, 2003
Posts: 29
Hi Rahul,

Im not quite sure how i can make a request outside the container and add attributes to it. Could you please help me out with that ?

Thanks,

Chetan
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Im not quite sure how i can make a request outside the container and add attributes to it.


It's not possible to dispatch a request to somewhere outside of the container (you could do a client-side redirect, though). What is discussed above is about dispatching to a different context in the same container. That works just like forwarding withing the same context, assuming it's enabled as mentioned before.
Chet Arora
Greenhorn

Joined: May 20, 2003
Posts: 29
Hi Ulf,

Thanks for your reply. What i need to do is this:

When a user clicks on a link on a specific page on my site, i need to redirect the user to another site but pass some request attributes in the redirection. How can i achieve this ?

Thanks,

Chetan
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
You cannot pass attributes , you can can pass string parameters to the new request URL using query string.
Pravin Jain
Ranch Hand

Joined: May 20, 2007
Posts: 60
you cannot pass attributes, but you could always manage parameters
by appending a query string to the url while redirecting, assuming
that the other url is a servlet expecting the parameters.


The Zen of Java Programming.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Forwarding to a URL outside the container
 
Similar Threads
How to change user of thread/process outside container
Request Dispatch Problem
init method
Doubt on servlet request lifecycle
whats the difference between forward and redirect?