Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redirection to remote servlet

 
Arnaud Burlet
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried HttpServletResponse.sendRedirect()?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jsp has the import tag... There must be something comparible in the servlet class itself... ?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic