• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forwarding to a URL outside the container

 
Chet Arora
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot pass attributes , you can can pass string parameters to the new request URL using query string.
 
Pravin Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic