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 redirection to remote servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "redirection to remote servlet" Watch "redirection to remote servlet" New topic
Author

redirection to remote servlet

Arnaud Burlet
Ranch Hand

Joined: Oct 08, 2004
Posts: 31
Hi, I need to find a way to redirect a servlet request to another remote servlet, and get the response. By "remote servlet" I mean "a servlet on another host" that has nothing to do with the first one. The first servlet can be seen as a proxy (doing some more than just forwarding the request).

I know it's possible to do that between 2 servlets of the same webapplication using a requestDispatcher, this is exactly the behaviour I need. But how to do it between 2 servlets ?
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
I believe that request dispatchers are only good for the web container they're living in. So, if you wanted to "dispatch" to a remove servlet, you would have to do the socket stuff yourself. I suggest you check out java.net package. (I think that's the one.)


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Have you tried HttpServletResponse.sendRedirect()?


James Carman, President<br />Carman Consulting, Inc.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by James Carman:
Have you tried HttpServletResponse.sendRedirect()?


It wouldn't work between two different web apps.
If you can do it in JSP. Try to redirect using JSTL.

Note: Even with JSTL the session wouldn't be shared
[ March 03, 2005: Message edited by: Adeel Ansari ]
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


Originally quoted by Adeel

quote:
--------------------------------------------------------------------------------
Originally posted by James Carman:
Have you tried HttpServletResponse.sendRedirect()?
--------------------------------------------------------------------------------

It wouldn't work between two different web apps.



Did you mean to say that the request would be redircted, but the request object would be lost if sendRedirect() is used
or
this simply wouldnt redirect at all

if used between two different web apps?

ram.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Following would work fine,

response.sendRedirect("http://ip: port/application")
response.sendRedirect("http://ip: port/application?action=getIdolSessions")
response.sendRedirect("http://www.askimam.com")

Note: session or application context wouldn't be shared between to apps

wouldn't work at all,

response.sendRedirect("www.askimam.com")
[ March 03, 2005: Message edited by: Adeel Ansari ]
Colin Fletcher
Ranch Hand

Joined: Sep 10, 2004
Posts: 200
Jsp has the import tag... There must be something comparible in the servlet class itself... ?


SCJP 1.4 SCWCD 1.4
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Colin Fletcher:
Jsp has the import tag... There must be something comparible in the servlet class itself... ?


you mean JSTL import. right?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: redirection to remote servlet