jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes call servlet to another webapplication using getRequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "call servlet to another webapplication using getRequestDispatcher" Watch "call servlet to another webapplication using getRequestDispatcher" New topic
Author

call servlet to another webapplication using getRequestDispatcher

Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 80
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You can't forward to another application. You can redirect, using sendRedirect()


GenRocket - Experts at Building Test Data
Eshwin Sukhdeve
Ranch Hand

Joined: Mar 15, 2012
Posts: 80
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I would use HttpClient to do that. Basically, making some sort of webservice call.
Ashwini Kashyap
Ranch Hand

Joined: Aug 30, 2012
Posts: 90
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: call servlet to another webapplication using getRequestDispatcher
 
Similar Threads
websphere assembly and deployment question
copy difference file from one server to another
inter servlet communication
Request Dispatcher problem
classpath for multiple web application.