Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

call servlet to another webapplication using getRequestDispatcher

 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't forward to another application. You can redirect, using sendRedirect()
 
Eshwin Sukhdeve
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use HttpClient to do that. Basically, making some sort of webservice call.
 
Ashwini Kashyap
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic