File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Redirecting the req to another server ? 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 "Redirecting the req to another server ?" Watch "Redirecting the req to another server ?" New topic
Author

Redirecting the req to another server ?

Arvind Sampath
Ranch Hand

Joined: May 11, 2005
Posts: 144
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Mar 03, 2005
Posts: 28
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

Joined: Oct 29, 2003
Posts: 254
He should redirect to the following address:

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

keywords being the url encoded keywords to search.


http://www.goodercode.com
SCJP 1.4
Arvind Sampath
Ranch Hand

Joined: May 11, 2005
Posts: 144
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

Joined: Mar 06, 2001
Posts: 13459

response.sendRedirect("http://www.google.com");

Forward slashes, not escaped backslashes please
Arvind Sampath
Ranch Hand

Joined: May 11, 2005
Posts: 144
Yep, It doesnt get sillier than this

Thanks David


Regards,
Arvind
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Redirecting the req to another server ?
 
Similar Threads
IllegalStateException: Cannot forward a response that is already committed
Diff Between redirect & forward
problem in redirect request object between 2 application servers
Jsp code doubt
How to get request object between 2 servers?