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.
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.
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.
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.
Joined: May 20, 2003
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 ?
Joined: Mar 22, 2005
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.
Joined: May 20, 2003
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 ?
Joined: Nov 29, 2005
You cannot pass attributes , you can can pass string parameters to the new request URL using query string.