Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Forwarding To Another Server

 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a servlet that is to reside on a server and its sole purpose is to forward any requests it receives to another servlet on another server. I have written the code below, which I know wont work because "context.getRequestDispatcher" is looking for a relative URL. My URL is on another machine though and I dont what I need to do differently to make that work.

Any help would be most appreciated. Thanks in advance....

ServletContext context = getServletContext();
RequestDispatcher dispatcher =
context.getRequestDispatcher("http://somemachine:8080/myapp/servlet/MyServlet");
dispatcher.forward(request, response);
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65545
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't make it work.

You'll need to redirect rather than forward.
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thanks much. Is that due to security or something like that?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Server side forwards are something that happen in-process within the server; all within one request thread.
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand, OK, thanks again for answering, much appreciated.
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!