| Author |
call servlet to another webapplication using getRequestDispatcher
|
Eshwin Sukhdeve
Ranch Hand
Joined: Mar 15, 2012
Posts: 78
|
|
Hi,
I have 2 webapplication (web1,web2)
in web1 I have 1 servlet class from that servlet class I want to call another servlet which is inside the web2. I have written the
following code
RequestDispatcher dispatcher =getServletContext().getRequestDispatcher("http://localhost:8080/web2/Servlet2");
dispatcher.forward(req,resp);
but it is giving me the error
java.lang.IllegalArgumentException: Path http://localhost:8080/web2/Servlet2 does not start with a "/" character
please can you tell me how to call that servlet.its urgent..I have seen this same que in this form..but not able to get it.
Thanks
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
|
You can't forward to another application. You can redirect, using sendRedirect()
|
 |
Eshwin Sukhdeve
Ranch Hand
Joined: Mar 15, 2012
Posts: 78
|
|
Thanks for reply,
actuly my perpose is that I have to read one file in the first webapp servlet and after reading I need to pass the content
of the file from first servlet to another webapp servlet.can you please tell me how to do that.
Thanks
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
|
I would use HttpClient to do that. Basically, making some sort of webservice call.
|
 |
Ashwini Kashyap
Ranch Hand
Joined: Aug 30, 2012
Posts: 61
|
|
Hi,
For forwarding request from a servlet to other servlet/resource and including the content of the resources like jsp or html WITHIN THAT APPLICATION can be achieved using RequestDispatcher.
For communicating between 2 applications, you can make use of HttpClient.
Thanks and Regards,
Ashwini Kashyap | akashyap@infocepts.com | www.infocepts.com
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15229
|
|
Ashwini Kashyap wrote:For forwarding request from a servlet to other servlet/resource and including the content of the resources like jsp or html WITHIN THAT APPLICATION can be achieved using RequestDispatcher.
For communicating between 2 applications, you can make use of HttpClient.
Thanks for repeating what has already been said.
|
 |
 |
|
|
subject: call servlet to another webapplication using getRequestDispatcher
|
|
|