Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirecting the req to another server ?

 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i redirect the request from my servlet to a program running in another server ?

I am trying to help out my friend who faces this issue in his college project. He is trying to develop a context based search engine. The servlet in his application is fetching the query the user types and does some manipulations + some business logic, forms a optimized query and is trying to send it to google. We tried using the RequestDispatcher to forward/redirect the request and we failed in succeding.

Is it really possible to forward a request to another server ? Am i making sense here?

Thanks in advance !

Regards,
Arvind
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are looking for response.sendRedirect(url)

Anything to dp with RequestDispatcher must be related to a resource inside the servlet container, you can't redirect or forward to an external resource.

Dave
 
sayan maity
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not possiblw with the help of requestdispatcher. Instead you can use JMS. But in that case also if should have access to the Google server. Here the concept of server clustering and caching will come.
 
Kerry Wilson
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He should redirect to the following address:

http://www.google.com/search?q=keywords

keywords being the url encoded keywords to search.
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are looking for response.sendRedirect(url)




I tried the above piece of code and failed to redirect again. Can u pls point out where am going wrong?

Regards,
Arvind
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.sendRedirect("http://www.google.com");

Forward slashes, not escaped backslashes please
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, It doesnt get sillier than this

Thanks David


Regards,
Arvind
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's called the Dilbert Principle: all of us at some stage will do something silly

I've solved the same basic configuration error in my system three times today :roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic