• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Forwarding To Another Server  RSS feed

 
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: 65833
134
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!